@ -54,27 +54,24 @@ class AnnotationTypeMappingsTests {
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( SimpleAnnotation . class ) ;
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( SimpleAnnotation . class ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( mappings . get ( 0 ) . getAnnotationType ( ) ) . isEqualTo ( SimpleAnnotation . class ) ;
assertThat ( mappings . get ( 0 ) . getAnnotationType ( ) ) . isEqualTo ( SimpleAnnotation . class ) ;
assertThat ( getAll ( mappings ) ) . flatExtracting (
assertThat ( getAll ( mappings ) ) . flatExtracting ( AnnotationTypeMapping : : getAnnotationType )
AnnotationTypeMapping : : getAnnotationType ) . containsExactly ( SimpleAnnotation . class ) ;
. containsExactly ( SimpleAnnotation . class ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenMetaAnnotationsReturnsMappings ( ) {
void forAnnotationTypeWhenMetaAnnotationsReturnsMappings ( ) {
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( MetaAnnotated . class ) ;
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( MetaAnnotated . class ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 6 ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 6 ) ;
assertThat ( getAll ( mappings ) ) . flatExtracting (
assertThat ( getAll ( mappings ) ) . flatExtracting ( AnnotationTypeMapping : : getAnnotationType )
AnnotationTypeMapping : : getAnnotationType ) . containsExactly (
. containsExactly ( MetaAnnotated . class , A . class , B . class , AA . class , AB . class , ABC . class ) ;
MetaAnnotated . class , A . class , B . class , AA . class , AB . class ,
ABC . class ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenHasRepeatingMetaAnnotationReturnsMapping ( ) {
void forAnnotationTypeWhenHasRepeatingMetaAnnotationReturnsMapping ( ) {
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( WithRepeatedMetaAnnotations . class ) ;
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( WithRepeatedMetaAnnotations . class ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 3 ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 3 ) ;
assertThat ( getAll ( mappings ) ) . flatExtracting (
assertThat ( getAll ( mappings ) ) . flatExtracting ( AnnotationTypeMapping : : getAnnotationType )
AnnotationTypeMapping : : getAnnotationType ) . containsExactly (
. containsExactly ( WithRepeatedMetaAnnotations . class , Repeating . class , Repeating . class ) ;
WithRepeatedMetaAnnotations . class , Repeating . class , Repeating . class ) ;
}
}
@Test
@Test
@ -89,56 +86,52 @@ class AnnotationTypeMappingsTests {
void forAnnotationTypeWhenSelfAnnotatedReturnsMapping ( ) {
void forAnnotationTypeWhenSelfAnnotatedReturnsMapping ( ) {
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( SelfAnnotated . class ) ;
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( SelfAnnotated . class ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( getAll ( mappings ) ) . flatExtracting (
assertThat ( getAll ( mappings ) ) . flatExtracting ( AnnotationTypeMapping : : getAnnotationType )
AnnotationTypeMapping : : getAnnotationType ) . containsExactly ( SelfAnnotated . class ) ;
. containsExactly ( SelfAnnotated . class ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenFormsLoopReturnsMapping ( ) {
void forAnnotationTypeWhenFormsLoopReturnsMapping ( ) {
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( LoopA . class ) ;
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( LoopA . class ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 2 ) ;
assertThat ( mappings . size ( ) ) . isEqualTo ( 2 ) ;
assertThat ( getAll ( mappings ) ) . flatExtracting (
assertThat ( getAll ( mappings ) ) . flatExtracting ( AnnotationTypeMapping : : getAnnotationType )
AnnotationTypeMapping : : getAnnotationType ) . containsExactly ( LoopA . class , LoopB . class ) ;
. containsExactly ( LoopA . class , LoopB . class ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenHasAliasForWithBothValueAndAttributeThrowsException ( ) {
void forAnnotationTypeWhenHasAliasForWithBothValueAndAttributeThrowsException ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasForWithBothValueAndAttribute . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForWithBothValueAndAttribute . class ) )
. withMessage ( "In @AliasFor declared on attribute 'test' in annotation ["
. withMessage ( "In @AliasFor declared on attribute 'test' in annotation [%s], attribute 'attribute' " +
+ AliasForWithBothValueAndAttribute . class . getName ( )
"and its alias 'value' are present with values of 'foo' and 'bar', but only one is permitted." ,
+ "], attribute 'attribute' and its alias 'value' are present with values of 'foo' and 'bar', but only one is permitted." ) ;
AliasForWithBothValueAndAttribute . class . getName ( ) ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenAliasForToSelfNonExistingAttribute ( ) {
void forAnnotationTypeWhenAliasForToSelfNonExistingAttribute ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasForToSelfNonExistingAttribute . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForToSelfNonExistingAttribute . class ) )
. withMessage ( "@AliasFor declaration on attribute 'test' in annotation ["
. withMessage ( "@AliasFor declaration on attribute 'test' in annotation [%s] " +
+ AliasForToSelfNonExistingAttribute . class . getName ( )
"declares an alias for 'missing' which is not present." ,
+ "] declares an alias for 'missing' which is not present." ) ;
AliasForToSelfNonExistingAttribute . class . getName ( ) ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenAliasForToOtherNonExistingAttribute ( ) {
void forAnnotationTypeWhenAliasForToOtherNonExistingAttribute ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasForToOtherNonExistingAttribute . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForToOtherNonExistingAttribute . class ) )
. withMessage ( "Attribute 'test' in annotation ["
. withMessage ( "Attribute 'test' in annotation [%s] is declared as an @AliasFor nonexistent " +
+ AliasForToOtherNonExistingAttribute . class . getName ( )
"attribute 'missing' in annotation [%s]." , AliasForToOtherNonExistingAttribute . class . getName ( ) ,
+ "] is declared as an @AliasFor nonexistent "
AliasForToOtherNonExistingAttributeTarget . class . getName ( ) ) ;
+ "attribute 'missing' in annotation ["
+ AliasForToOtherNonExistingAttributeTarget . class . getName ( )
+ "]." ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenAliasForToSelf ( ) {
void forAnnotationTypeWhenAliasForToSelf ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasForToSelf . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForToSelf . class ) )
. withMessage ( "@AliasFor declaration on attribute 'test' in annotation ["
. withMessage ( "@AliasFor declaration on attribute 'test' in annotation [%s] points to itself. " +
+ AliasForToSelf . class . getName ( )
"Specify 'annotation' to point to a same-named attribute on a meta-annotation." ,
+ "] points to itself. Specify 'annotation' to point to "
AliasForToSelf . class . getName ( ) ) ;
+ "a same-named attribute on a meta-annotation." ) ;
}
}
@Test
@Test
@ -152,13 +145,12 @@ class AnnotationTypeMappingsTests {
@Test
@Test
void forAnnotationTypeWhenAliasForWithIncompatibleReturnTypes ( ) {
void forAnnotationTypeWhenAliasForWithIncompatibleReturnTypes ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasForWithIncompatibleReturnTypes . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForWithIncompatibleReturnTypes . class ) )
. withMessage ( "Misconfigured aliases: attribute 'test' in annotation ["
. withMessage ( "Misconfigured aliases: attribute 'test' in annotation [%s] and attribute 'test' " +
+ AliasForWithIncompatibleReturnTypes . class . getName ( )
"in annotation [%s] must declare the same return type." ,
+ "] and attribute 'test' in annotation ["
AliasForWithIncompatibleReturnTypes . class . getName ( ) ,
+ AliasForWithIncompatibleReturnTypesTarget . class . getName ( )
AliasForWithIncompatibleReturnTypesTarget . class . getName ( ) ) ;
+ "] must declare the same return type." ) ;
}
}
@Test
@Test
@ -166,9 +158,8 @@ class AnnotationTypeMappingsTests {
String annotationType = AliasForToSelfAnnotatedToOtherAttribute . class . getName ( ) ;
String annotationType = AliasForToSelfAnnotatedToOtherAttribute . class . getName ( ) ;
assertThatExceptionOfType ( AnnotationConfigurationException . class )
assertThatExceptionOfType ( AnnotationConfigurationException . class )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForToSelfAnnotatedToOtherAttribute . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForToSelfAnnotatedToOtherAttribute . class ) )
. withMessage ( "Attribute 'b' in annotation [" + annotationType
. withMessage ( "Attribute 'b' in annotation [%1$s] must be declared as an @AliasFor attribute 'a' in " +
+ "] must be declared as an @AliasFor attribute 'a' in annotation [" + annotationType
"annotation [%1$s], not attribute 'c' in annotation [%1$s]." , annotationType ) ;
+ "], not attribute 'c' in annotation [" + annotationType + "]." ) ;
}
}
@Test
@Test
@ -182,53 +173,45 @@ class AnnotationTypeMappingsTests {
String metaAnnotationName = AliasPair . class . getName ( ) ;
String metaAnnotationName = AliasPair . class . getName ( ) ;
assertThatExceptionOfType ( AnnotationConfigurationException . class )
assertThatExceptionOfType ( AnnotationConfigurationException . class )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( annotationType ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( annotationType ) )
. withMessage ( "Attribute 'b' in annotation [" + annotationName
. withMessage ( "Attribute 'b' in annotation [" + annotationName +
+ "] must be declared as an @AliasFor attribute 'a' in annotation [" + annotationName
"] must be declared as an @AliasFor attribute 'a' in annotation [" + annotationName +
+ "], not attribute '" + overriddenAttribute + "' in annotation [" + metaAnnotationName + "]." ) ;
"], not attribute '" + overriddenAttribute + "' in annotation [" + metaAnnotationName + "]." ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenAliasForNonMetaAnnotated ( ) {
void forAnnotationTypeWhenAliasForNonMetaAnnotated ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasForNonMetaAnnotated . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForNonMetaAnnotated . class ) )
. withMessage ( "@AliasFor declaration on attribute 'test' in annotation ["
. withMessage ( "@AliasFor declaration on attribute 'test' in annotation [" + AliasForNonMetaAnnotated . class . getName ( ) +
+ AliasForNonMetaAnnotated . class . getName ( )
"] declares an alias for attribute 'test' in annotation [" + AliasForNonMetaAnnotatedTarget . class . getName ( ) +
+ "] declares an alias for attribute 'test' in annotation ["
"] which is not meta-present." ) ;
+ AliasForNonMetaAnnotatedTarget . class . getName ( )
+ "] which is not meta-present." ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenAliasForSelfWithDifferentDefaults ( ) {
void forAnnotationTypeWhenAliasForSelfWithDifferentDefaults ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasForSelfWithDifferentDefaults . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForSelfWithDifferentDefaults . class ) )
. withMessage ( "Misconfigured aliases: attribute 'a' in annotation ["
. withMessage ( "Misconfigured aliases: attribute 'a' in annotation [" + AliasForSelfWithDifferentDefaults . class . getName ( ) +
+ AliasForSelfWithDifferentDefaults . class . getName ( )
"] and attribute 'b' in annotation [" + AliasForSelfWithDifferentDefaults . class . getName ( ) +
+ "] and attribute 'b' in annotation ["
"] must declare the same default value." ) ;
+ AliasForSelfWithDifferentDefaults . class . getName ( )
+ "] must declare the same default value." ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenAliasForSelfWithMissingDefault ( ) {
void forAnnotationTypeWhenAliasForSelfWithMissingDefault ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasForSelfWithMissingDefault . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasForSelfWithMissingDefault . class ) )
. withMessage ( "Misconfigured aliases: attribute 'a' in annotation ["
. withMessage ( "Misconfigured aliases: attribute 'a' in annotation [" + AliasForSelfWithMissingDefault . class . getName ( ) +
+ AliasForSelfWithMissingDefault . class . getName ( )
"] and attribute 'b' in annotation [" + AliasForSelfWithMissingDefault . class . getName ( ) +
+ "] and attribute 'b' in annotation ["
"] must declare default values." ) ;
+ AliasForSelfWithMissingDefault . class . getName ( )
+ "] must declare default values." ) ;
}
}
@Test
@Test
void forAnnotationTypeWhenAliasWithExplicitMirrorAndDifferentDefaults ( ) {
void forAnnotationTypeWhenAliasWithExplicitMirrorAndDifferentDefaults ( ) {
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
AnnotationTypeMappings . forAnnotationType ( AliasWithExplicitMirrorAndDifferentDefaults . class ) )
. isThrownBy ( ( ) - > AnnotationTypeMappings . forAnnotationType ( AliasWithExplicitMirrorAndDifferentDefaults . class ) )
. withMessage ( "Misconfigured aliases: attribute 'a' in annotation ["
. withMessage ( "Misconfigured aliases: attribute 'a' in annotation [" + AliasWithExplicitMirrorAndDifferentDefaults . class . getName ( ) +
+ AliasWithExplicitMirrorAndDifferentDefaults . class . getName ( )
"] and attribute 'c' in annotation [" + AliasWithExplicitMirrorAndDifferentDefaults . class . getName ( ) +
+ "] and attribute 'c' in annotation ["
"] must declare the same default value." ) ;
+ AliasWithExplicitMirrorAndDifferentDefaults . class . getName ( )
+ "] must declare the same default value." ) ;
}
}
@Test
@Test
@ -369,18 +352,16 @@ class AnnotationTypeMappingsTests {
@Test
@Test
void resolveMirrorsWhenHasDifferentValuesThrowsException ( ) {
void resolveMirrorsWhenHasDifferentValuesThrowsException ( ) {
AnnotationTypeMapping mapping = AnnotationTypeMappings . forAnnotationType ( AliasPair . class ) . get ( 0 ) ;
AnnotationTypeMapping mapping = AnnotationTypeMappings . forAnnotationType ( AliasPair . class ) . get ( 0 ) ;
assertThatExceptionOfType ( AnnotationConfigurationException . class ) . isThrownBy ( ( ) - >
assertThatExceptionOfType ( AnnotationConfigurationException . class )
resolveMirrorSets ( mapping , WithDifferentValueAliasPair . class , AliasPair . class ) )
. isThrownBy ( ( ) - > resolveMirrorSets ( mapping , WithDifferentValueAliasPair . class , AliasPair . class ) )
. withMessage ( "Different @AliasFor mirror values for annotation ["
. withMessage ( "Different @AliasFor mirror values for annotation [" + AliasPair . class . getName ( ) + "] declared on " +
+ AliasPair . class . getName ( ) + "] declared on "
WithDifferentValueAliasPair . class . getName ( ) +
+ WithDifferentValueAliasPair . class . getName ( )
"; attribute 'a' and its alias 'b' are declared with values of [test1] and [test2]." ) ;
+ "; attribute 'a' and its alias 'b' are declared with values of [test1] and [test2]." ) ;
}
}
@Test
@Test
void resolveMirrorsWhenHasWithMultipleRoutesToAliasReturnsMirrors ( ) {
void resolveMirrorsWhenHasWithMultipleRoutesToAliasReturnsMirrors ( ) {
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType (
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( MultipleRoutesToAliasA . class ) ;
MultipleRoutesToAliasA . class ) ;
AnnotationTypeMapping mappingsA = getMapping ( mappings , MultipleRoutesToAliasA . class ) ;
AnnotationTypeMapping mappingsA = getMapping ( mappings , MultipleRoutesToAliasA . class ) ;
assertThat ( mappingsA . getMirrorSets ( ) . size ( ) ) . isZero ( ) ;
assertThat ( mappingsA . getMirrorSets ( ) . size ( ) ) . isZero ( ) ;
AnnotationTypeMapping mappingsB = getMapping ( mappings , MultipleRoutesToAliasB . class ) ;
AnnotationTypeMapping mappingsB = getMapping ( mappings , MultipleRoutesToAliasB . class ) ;
@ -391,8 +372,7 @@ class AnnotationTypeMappingsTests {
@Test
@Test
void getAliasMappingWhenHasWithMultipleRoutesToAliasReturnsMappedAttributes ( ) {
void getAliasMappingWhenHasWithMultipleRoutesToAliasReturnsMappedAttributes ( ) {
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType (
AnnotationTypeMappings mappings = AnnotationTypeMappings . forAnnotationType ( MultipleRoutesToAliasA . class ) ;
MultipleRoutesToAliasA . class ) ;
AnnotationTypeMapping mappingsA = getMapping ( mappings , MultipleRoutesToAliasA . class ) ;
AnnotationTypeMapping mappingsA = getMapping ( mappings , MultipleRoutesToAliasA . class ) ;
assertThat ( getAliasMapping ( mappingsA , 0 ) ) . isNull ( ) ;
assertThat ( getAliasMapping ( mappingsA , 0 ) ) . isNull ( ) ;
AnnotationTypeMapping mappingsB = getMapping ( mappings , MultipleRoutesToAliasB . class ) ;
AnnotationTypeMapping mappingsB = getMapping ( mappings , MultipleRoutesToAliasB . class ) ;