@@ -1395,9 +1395,10 @@ void synthesizeAlreadySynthesized() throws Exception {
1395
1395
RequestMapping synthesizedWebMapping = MergedAnnotation .from (webMapping ).synthesize ();
1396
1396
RequestMapping synthesizedAgainWebMapping = MergedAnnotation .from (synthesizedWebMapping ).synthesize ();
1397
1397
1398
- assertThat (synthesizedWebMapping ). isInstanceOf ( SynthesizedAnnotation . class );
1399
- assertThat (synthesizedAgainWebMapping ). isInstanceOf ( SynthesizedAnnotation . class );
1398
+ assertSynthesized (synthesizedWebMapping );
1399
+ assertSynthesized (synthesizedAgainWebMapping );
1400
1400
assertThat (synthesizedWebMapping ).isEqualTo (synthesizedAgainWebMapping );
1401
+ assertThat (synthesizedWebMapping ).isSameAs (synthesizedAgainWebMapping );
1401
1402
assertThat (synthesizedWebMapping .name ()).isEqualTo ("foo" );
1402
1403
assertThat (synthesizedWebMapping .path ()).containsExactly ("/test" );
1403
1404
assertThat (synthesizedWebMapping .value ()).containsExactly ("/test" );
@@ -1412,15 +1413,15 @@ void synthesizeShouldNotSynthesizeNonsynthesizableAnnotations() throws Exception
1412
1413
Id synthesizedId = MergedAnnotation .from (id ).synthesize ();
1413
1414
assertThat (id ).isEqualTo (synthesizedId );
1414
1415
// It doesn't make sense to synthesize @Id since it declares zero attributes.
1415
- assertThat (synthesizedId ). isNotInstanceOf ( SynthesizedAnnotation . class );
1416
+ assertNotSynthesized (synthesizedId );
1416
1417
assertThat (id ).isSameAs (synthesizedId );
1417
1418
1418
1419
GeneratedValue generatedValue = method .getAnnotation (GeneratedValue .class );
1419
1420
assertThat (generatedValue ).isNotNull ();
1420
1421
GeneratedValue synthesizedGeneratedValue = MergedAnnotation .from (generatedValue ).synthesize ();
1421
1422
assertThat (generatedValue ).isEqualTo (synthesizedGeneratedValue );
1422
1423
// It doesn't make sense to synthesize @GeneratedValue since it declares zero attributes with aliases.
1423
- assertThat (synthesizedGeneratedValue ). isNotInstanceOf ( SynthesizedAnnotation . class );
1424
+ assertNotSynthesized (synthesizedGeneratedValue );
1424
1425
assertThat (generatedValue ).isSameAs (synthesizedGeneratedValue );
1425
1426
}
1426
1427
@@ -1430,30 +1431,30 @@ void synthesizeWhenUsingMergedAnnotationsFromApi() {
1430
1431
MergedAnnotations mergedAnnotations = MergedAnnotations .from (directlyAnnotatedField );
1431
1432
RootAnnotation rootAnnotation = mergedAnnotations .get (RootAnnotation .class ).synthesize ();
1432
1433
assertThat (rootAnnotation .flag ()).isFalse ();
1433
- assertThat (rootAnnotation ). isNotInstanceOf ( SynthesizedAnnotation . class );
1434
+ assertNotSynthesized (rootAnnotation );
1434
1435
1435
1436
Field metaAnnotatedField = ReflectionUtils .findField (DomainType .class , "metaAnnotated" );
1436
1437
mergedAnnotations = MergedAnnotations .from (metaAnnotatedField );
1437
1438
rootAnnotation = mergedAnnotations .get (RootAnnotation .class ).synthesize ();
1438
1439
assertThat (rootAnnotation .flag ()).isTrue ();
1439
- assertThat (rootAnnotation ). isInstanceOf ( SynthesizedAnnotation . class );
1440
+ assertSynthesized (rootAnnotation );
1440
1441
1441
1442
Field metaMetaAnnotatedField = ReflectionUtils .findField (DomainType .class , "metaMetaAnnotated" );
1442
1443
mergedAnnotations = MergedAnnotations .from (metaMetaAnnotatedField );
1443
1444
rootAnnotation = mergedAnnotations .get (RootAnnotation .class ).synthesize ();
1444
1445
assertThat (rootAnnotation .flag ()).isTrue ();
1445
- assertThat (rootAnnotation ). isInstanceOf ( SynthesizedAnnotation . class );
1446
+ assertSynthesized (rootAnnotation );
1446
1447
}
1447
1448
1448
1449
@ Test // gh-28704
1449
1450
void synthesizeShouldNotSynthesizeNonsynthesizableAnnotationsWhenUsingMergedAnnotationsFromApi () {
1450
1451
MergedAnnotations mergedAnnotations = MergedAnnotations .from (SecurityConfig .class );
1451
1452
1452
1453
EnableWebSecurity enableWebSecurity = mergedAnnotations .get (EnableWebSecurity .class ).synthesize ();
1453
- assertThat (enableWebSecurity ). isNotInstanceOf ( SynthesizedAnnotation . class );
1454
+ assertNotSynthesized (enableWebSecurity );
1454
1455
1455
1456
EnableGlobalAuthentication enableGlobalAuthentication = mergedAnnotations .get (EnableGlobalAuthentication .class ).synthesize ();
1456
- assertThat (enableGlobalAuthentication ). isNotInstanceOf ( SynthesizedAnnotation . class );
1457
+ assertNotSynthesized (enableGlobalAuthentication );
1457
1458
}
1458
1459
1459
1460
/**
@@ -1472,8 +1473,8 @@ void synthesizeShouldNotResynthesizeAlreadySynthesizedAnnotations() throws Excep
1472
1473
RequestMapping synthesizedWebMapping1 = mergedAnnotation1 .synthesize ();
1473
1474
RequestMapping synthesizedWebMapping2 = MergedAnnotation .from (webMapping ).synthesize ();
1474
1475
1475
- assertThat (synthesizedWebMapping1 ). isInstanceOf ( SynthesizedAnnotation . class );
1476
- assertThat (synthesizedWebMapping2 ). isInstanceOf ( SynthesizedAnnotation . class );
1476
+ assertSynthesized (synthesizedWebMapping1 );
1477
+ assertSynthesized (synthesizedWebMapping2 );
1477
1478
assertThat (synthesizedWebMapping1 ).isEqualTo (synthesizedWebMapping2 );
1478
1479
1479
1480
// Synthesizing an annotation from a different MergedAnnotation results in a different synthesized annotation instance.
@@ -1595,14 +1596,11 @@ void synthesizeWithImplicitAliases() throws Exception {
1595
1596
testSynthesisWithImplicitAliases (GroovyImplicitAliasesSimpleTestConfigurationClass .class , "groovyScript" );
1596
1597
}
1597
1598
1598
- private void testSynthesisWithImplicitAliases (Class <?> clazz , String expected )
1599
- throws Exception {
1600
- ImplicitAliasesTestConfiguration config = clazz .getAnnotation (
1601
- ImplicitAliasesTestConfiguration .class );
1599
+ private void testSynthesisWithImplicitAliases (Class <?> clazz , String expected ) throws Exception {
1600
+ ImplicitAliasesTestConfiguration config = clazz .getAnnotation (ImplicitAliasesTestConfiguration .class );
1602
1601
assertThat (config ).isNotNull ();
1603
- ImplicitAliasesTestConfiguration synthesized = MergedAnnotation .from (
1604
- config ).synthesize ();
1605
- assertThat (synthesized ).isInstanceOf (SynthesizedAnnotation .class );
1602
+ ImplicitAliasesTestConfiguration synthesized = MergedAnnotation .from (config ).synthesize ();
1603
+ assertSynthesized (synthesized );
1606
1604
assertThat (synthesized .value ()).isEqualTo (expected );
1607
1605
assertThat (synthesized .location1 ()).isEqualTo (expected );
1608
1606
assertThat (synthesized .xmlFile ()).isEqualTo (expected );
@@ -1630,7 +1628,7 @@ private void testSynthesisWithImplicitAliasesWithImpliedAliasNamesOmitted(
1630
1628
assertThat (config ).isNotNull ();
1631
1629
ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration synthesized =
1632
1630
MergedAnnotation .from (config ).synthesize ();
1633
- assertThat (synthesized ). isInstanceOf ( SynthesizedAnnotation . class );
1631
+ assertSynthesized (synthesized );
1634
1632
assertThat (synthesized .value ()).isEqualTo (expected );
1635
1633
assertThat (synthesized .location ()).isEqualTo (expected );
1636
1634
assertThat (synthesized .xmlFile ()).isEqualTo (expected );
@@ -1642,7 +1640,7 @@ void synthesizeWithImplicitAliasesForAliasPair() throws Exception {
1642
1640
ImplicitAliasesForAliasPairTestConfigurationClass .class .getAnnotation (
1643
1641
ImplicitAliasesForAliasPairTestConfiguration .class );
1644
1642
ImplicitAliasesForAliasPairTestConfiguration synthesized = MergedAnnotation .from (config ).synthesize ();
1645
- assertThat (synthesized ). isInstanceOf ( SynthesizedAnnotation . class );
1643
+ assertSynthesized (synthesized );
1646
1644
assertThat (synthesized .xmlFile ()).isEqualTo ("test.xml" );
1647
1645
assertThat (synthesized .groovyScript ()).isEqualTo ("test.xml" );
1648
1646
}
@@ -1653,7 +1651,7 @@ void synthesizeWithTransitiveImplicitAliases() throws Exception {
1653
1651
TransitiveImplicitAliasesTestConfigurationClass .class .getAnnotation (
1654
1652
TransitiveImplicitAliasesTestConfiguration .class );
1655
1653
TransitiveImplicitAliasesTestConfiguration synthesized = MergedAnnotation .from (config ).synthesize ();
1656
- assertThat (synthesized ). isInstanceOf ( SynthesizedAnnotation . class );
1654
+ assertSynthesized (synthesized );
1657
1655
assertThat (synthesized .xml ()).isEqualTo ("test.xml" );
1658
1656
assertThat (synthesized .groovy ()).isEqualTo ("test.xml" );
1659
1657
}
@@ -1665,7 +1663,7 @@ void synthesizeWithTransitiveImplicitAliasesForAliasPair() throws Exception {
1665
1663
TransitiveImplicitAliasesForAliasPairTestConfiguration .class );
1666
1664
TransitiveImplicitAliasesForAliasPairTestConfiguration synthesized = MergedAnnotation .from (
1667
1665
config ).synthesize ();
1668
- assertThat (synthesized ). isInstanceOf ( SynthesizedAnnotation . class );
1666
+ assertSynthesized (synthesized );
1669
1667
assertThat (synthesized .xml ()).isEqualTo ("test.xml" );
1670
1668
assertThat (synthesized .groovy ()).isEqualTo ("test.xml" );
1671
1669
}
@@ -1724,7 +1722,7 @@ void synthesizeFromMapWithoutAttributeAliases() throws Exception {
1724
1722
Map <String , Object > map = Collections .singletonMap ("value" , "webController" );
1725
1723
MergedAnnotation <Component > annotation = MergedAnnotation .of (Component .class , map );
1726
1724
Component synthesizedComponent = annotation .synthesize ();
1727
- assertThat (synthesizedComponent ). isInstanceOf ( SynthesizedAnnotation . class );
1725
+ assertSynthesized (synthesizedComponent );
1728
1726
assertThat (synthesizedComponent .value ()).isEqualTo ("webController" );
1729
1727
}
1730
1728
@@ -1745,7 +1743,7 @@ void synthesizeFromMapWithNestedMap() throws Exception {
1745
1743
MergedAnnotation <ComponentScanSingleFilter > annotation = MergedAnnotation .of (
1746
1744
ComponentScanSingleFilter .class , map );
1747
1745
ComponentScanSingleFilter synthesizedComponentScan = annotation .synthesize ();
1748
- assertThat (synthesizedComponentScan ). isInstanceOf ( SynthesizedAnnotation . class );
1746
+ assertSynthesized (synthesizedComponentScan );
1749
1747
assertThat (synthesizedComponentScan .value ().pattern ()).isEqualTo ("newFoo" );
1750
1748
}
1751
1749
@@ -1769,7 +1767,7 @@ void synthesizeFromMapWithNestedArrayOfMaps() throws Exception {
1769
1767
MergedAnnotation <ComponentScan > annotation = MergedAnnotation .of (
1770
1768
ComponentScan .class , map );
1771
1769
ComponentScan synthesizedComponentScan = annotation .synthesize ();
1772
- assertThat (synthesizedComponentScan ). isInstanceOf ( SynthesizedAnnotation . class );
1770
+ assertSynthesized (synthesizedComponentScan );
1773
1771
assertThat (Arrays .stream (synthesizedComponentScan .excludeFilters ()).map (
1774
1772
Filter ::pattern )).containsExactly ("newFoo" , "newBar" );
1775
1773
}
@@ -1888,7 +1886,7 @@ void synthesizeFromAnnotationAttributesWithoutAttributeAliases() throws Exceptio
1888
1886
assertThat (component ).isNotNull ();
1889
1887
Map <String , Object > attributes = MergedAnnotation .from (component ).asMap ();
1890
1888
Component synthesized = MergedAnnotation .of (Component .class , attributes ).synthesize ();
1891
- assertThat (synthesized ). isInstanceOf ( SynthesizedAnnotation . class );
1889
+ assertSynthesized (synthesized );
1892
1890
assertThat (synthesized ).isEqualTo (component );
1893
1891
}
1894
1892
@@ -2047,7 +2045,7 @@ void synthesizeNonPublicWithAttributeAliasesFromDifferentPackage() throws Except
2047
2045
assertThat (annotation ).isNotNull ();
2048
2046
MergedAnnotation <Annotation > mergedAnnotation = MergedAnnotation .from (annotation );
2049
2047
Annotation synthesizedAnnotation = mergedAnnotation .synthesize ();
2050
- assertThat (synthesizedAnnotation ). isInstanceOf ( SynthesizedAnnotation . class );
2048
+ assertSynthesized (synthesizedAnnotation );
2051
2049
assertThat (mergedAnnotation .getString ("name" )).isEqualTo ("test" );
2052
2050
assertThat (mergedAnnotation .getString ("path" )).isEqualTo ("/test" );
2053
2051
assertThat (mergedAnnotation .getString ("value" )).isEqualTo ("/test" );
@@ -2058,10 +2056,10 @@ void synthesizeWithArrayOfAnnotations() throws Exception {
2058
2056
Hierarchy hierarchy = HierarchyClass .class .getAnnotation (Hierarchy .class );
2059
2057
assertThat (hierarchy ).isNotNull ();
2060
2058
Hierarchy synthesizedHierarchy = MergedAnnotation .from (hierarchy ).synthesize ();
2061
- assertThat (synthesizedHierarchy ). isInstanceOf ( SynthesizedAnnotation . class );
2059
+ assertSynthesized (synthesizedHierarchy );
2062
2060
TestConfiguration [] configs = synthesizedHierarchy .value ();
2063
2061
assertThat (configs ).isNotNull ();
2064
- assertThat (configs ).allMatch (SynthesizedAnnotation . class :: isInstance );
2062
+ assertThat (configs ).allMatch (AnnotationUtils :: isSynthesizedAnnotation );
2065
2063
assertThat (configs ).extracting (TestConfiguration ::value ).containsExactly ("A" , "B" );
2066
2064
assertThat (configs ).extracting (TestConfiguration ::location ).containsExactly ("A" , "B" );
2067
2065
@@ -2082,7 +2080,7 @@ void synthesizeWithArrayOfChars() throws Exception {
2082
2080
assertThat (charsContainer ).isNotNull ();
2083
2081
CharsContainer synthesizedCharsContainer = MergedAnnotation .from (
2084
2082
charsContainer ).synthesize ();
2085
- assertThat (synthesizedCharsContainer ). isInstanceOf ( SynthesizedAnnotation . class );
2083
+ assertSynthesized (synthesizedCharsContainer );
2086
2084
char [] chars = synthesizedCharsContainer .chars ();
2087
2085
assertThat (chars ).containsExactly ('x' , 'y' , 'z' );
2088
2086
// Alter array returned from synthesized annotation
@@ -3682,4 +3680,12 @@ static class ValueAttributeMetaMetaClass {
3682
3680
}
3683
3681
// @formatter:on
3684
3682
3683
+ static void assertSynthesized (Annotation annotation ) {
3684
+ assertThat (AnnotationUtils .isSynthesizedAnnotation (annotation )).as ("synthesized annotation" ).isTrue ();
3685
+ }
3686
+
3687
+ static void assertNotSynthesized (Annotation annotation ) {
3688
+ assertThat (AnnotationUtils .isSynthesizedAnnotation (annotation )).as ("synthesized annotation" ).isFalse ();
3689
+ }
3690
+
3685
3691
}
0 commit comments