Implement hashCode() for synthesized annotations
Issue: SPR-13066
This commit is contained in:
@@ -694,6 +694,44 @@ public class AnnotationUtilsTests {
|
||||
assertThat(webMappingWithAliases, is(not(synthesizedWebMapping1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeForSynthesizedAnnotations() throws Exception {
|
||||
Method methodWithPath = WebController.class.getMethod("handleMappedWithPathAttribute");
|
||||
WebMapping webMappingWithAliases = methodWithPath.getAnnotation(WebMapping.class);
|
||||
assertNotNull(webMappingWithAliases);
|
||||
|
||||
Method methodWithPathAndValue = WebController.class.getMethod("handleMappedWithSamePathAndValueAttributes");
|
||||
WebMapping webMappingWithPathAndValue = methodWithPathAndValue.getAnnotation(WebMapping.class);
|
||||
assertNotNull(webMappingWithPathAndValue);
|
||||
|
||||
WebMapping synthesizedWebMapping1 = synthesizeAnnotation(webMappingWithAliases);
|
||||
assertNotNull(synthesizedWebMapping1);
|
||||
WebMapping synthesizedWebMapping2 = synthesizeAnnotation(webMappingWithAliases);
|
||||
assertNotNull(synthesizedWebMapping2);
|
||||
|
||||
// Equality amongst standard annotations
|
||||
assertThat(webMappingWithAliases.hashCode(), is(webMappingWithAliases.hashCode()));
|
||||
assertThat(webMappingWithPathAndValue.hashCode(), is(webMappingWithPathAndValue.hashCode()));
|
||||
|
||||
// Inequality amongst standard annotations
|
||||
assertThat(webMappingWithAliases.hashCode(), is(not(webMappingWithPathAndValue.hashCode())));
|
||||
assertThat(webMappingWithPathAndValue.hashCode(), is(not(webMappingWithAliases.hashCode())));
|
||||
|
||||
// Equality amongst synthesized annotations
|
||||
assertThat(synthesizedWebMapping1.hashCode(), is(synthesizedWebMapping1.hashCode()));
|
||||
assertThat(synthesizedWebMapping2.hashCode(), is(synthesizedWebMapping2.hashCode()));
|
||||
assertThat(synthesizedWebMapping1.hashCode(), is(synthesizedWebMapping2.hashCode()));
|
||||
assertThat(synthesizedWebMapping2.hashCode(), is(synthesizedWebMapping1.hashCode()));
|
||||
|
||||
// Equality between standard and synthesized annotations
|
||||
assertThat(synthesizedWebMapping1.hashCode(), is(webMappingWithPathAndValue.hashCode()));
|
||||
assertThat(webMappingWithPathAndValue.hashCode(), is(synthesizedWebMapping1.hashCode()));
|
||||
|
||||
// Inequality between standard and synthesized annotations
|
||||
assertThat(synthesizedWebMapping1.hashCode(), is(not(webMappingWithAliases.hashCode())));
|
||||
assertThat(webMappingWithAliases.hashCode(), is(not(synthesizedWebMapping1.hashCode())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fully reflection-based test that verifies support for
|
||||
* {@linkplain AnnotationUtils#synthesizeAnnotation synthesizing annotations}
|
||||
|
||||
Reference in New Issue
Block a user