Implement equals() for synthesized annotations

Issue: SPR-13065
This commit is contained in:
Sam Brannen
2015-05-23 22:23:34 +02:00
parent c622f4c487
commit 7bf609f111
2 changed files with 71 additions and 10 deletions
@@ -656,6 +656,44 @@ public class AnnotationUtilsTests {
assertThat(string, endsWith(")"));
}
@Test
public void equalsForSynthesizedAnnotations() 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, is(webMappingWithAliases));
assertThat(webMappingWithPathAndValue, is(webMappingWithPathAndValue));
// Inequality amongst standard annotations
assertThat(webMappingWithAliases, is(not(webMappingWithPathAndValue)));
assertThat(webMappingWithPathAndValue, is(not(webMappingWithAliases)));
// Equality amongst synthesized annotations
assertThat(synthesizedWebMapping1, is(synthesizedWebMapping1));
assertThat(synthesizedWebMapping2, is(synthesizedWebMapping2));
assertThat(synthesizedWebMapping1, is(synthesizedWebMapping2));
assertThat(synthesizedWebMapping2, is(synthesizedWebMapping1));
// Equality between standard and synthesized annotations
assertThat(synthesizedWebMapping1, is(webMappingWithPathAndValue));
assertThat(webMappingWithPathAndValue, is(synthesizedWebMapping1));
// Inequality between standard and synthesized annotations
assertThat(synthesizedWebMapping1, is(not(webMappingWithAliases)));
assertThat(webMappingWithAliases, is(not(synthesizedWebMapping1)));
}
/**
* Fully reflection-based test that verifies support for
* {@linkplain AnnotationUtils#synthesizeAnnotation synthesizing annotations}