@@ -288,8 +288,8 @@ public void getMergedAnnotationAttributesWithConventionBasedComposedAnnotation()
288
288
AnnotationAttributes attributes = getMergedAnnotationAttributes (element , name );
289
289
290
290
assertNotNull ("Should find @ContextConfig on " + element .getSimpleName (), attributes );
291
- assertArrayEquals ("locations" , new String [] { "explicitDeclaration" } , attributes .getStringArray ("locations" ));
292
- assertArrayEquals ("value" , new String [] { "explicitDeclaration" } , attributes .getStringArray ("value" ));
291
+ assertArrayEquals ("locations" , asArray ( "explicitDeclaration" ) , attributes .getStringArray ("locations" ));
292
+ assertArrayEquals ("value" , asArray ( "explicitDeclaration" ) , attributes .getStringArray ("value" ));
293
293
294
294
// Verify contracts between utility methods:
295
295
assertTrue (isAnnotated (element , name ));
@@ -305,7 +305,7 @@ public void getMergedAnnotationAttributesWithHalfConventionBasedAndHalfAliasedCo
305
305
}
306
306
307
307
private void getMergedAnnotationAttributesWithHalfConventionBasedAndHalfAliasedComposedAnnotation (Class <?> clazz ) {
308
- String [] expected = new String [] { "explicitDeclaration" } ;
308
+ String [] expected = asArray ( "explicitDeclaration" ) ;
309
309
String name = ContextConfig .class .getName ();
310
310
String simpleName = clazz .getSimpleName ();
311
311
AnnotationAttributes attributes = getMergedAnnotationAttributes (clazz , name );
@@ -325,8 +325,8 @@ public void getMergedAnnotationAttributesWithAliasedComposedAnnotation() {
325
325
AnnotationAttributes attributes = getMergedAnnotationAttributes (element , name );
326
326
327
327
assertNotNull ("Should find @ContextConfig on " + element .getSimpleName (), attributes );
328
- assertArrayEquals ("value" , new String [] { "test.xml" } , attributes .getStringArray ("value" ));
329
- assertArrayEquals ("locations" , new String [] { "test.xml" } , attributes .getStringArray ("locations" ));
328
+ assertArrayEquals ("value" , asArray ( "test.xml" ) , attributes .getStringArray ("value" ));
329
+ assertArrayEquals ("locations" , asArray ( "test.xml" ) , attributes .getStringArray ("locations" ));
330
330
331
331
// Verify contracts between utility methods:
332
332
assertTrue (isAnnotated (element , name ));
@@ -339,8 +339,8 @@ public void getMergedAnnotationAttributesWithAliasedValueComposedAnnotation() {
339
339
AnnotationAttributes attributes = getMergedAnnotationAttributes (element , name );
340
340
341
341
assertNotNull ("Should find @ContextConfig on " + element .getSimpleName (), attributes );
342
- assertArrayEquals ("locations" , new String [] { "test.xml" } , attributes .getStringArray ("locations" ));
343
- assertArrayEquals ("value" , new String [] { "test.xml" } , attributes .getStringArray ("value" ));
342
+ assertArrayEquals ("locations" , asArray ( "test.xml" ) , attributes .getStringArray ("locations" ));
343
+ assertArrayEquals ("value" , asArray ( "test.xml" ) , attributes .getStringArray ("value" ));
344
344
345
345
// Verify contracts between utility methods:
346
346
assertTrue (isAnnotated (element , name ));
@@ -351,7 +351,7 @@ public void getMergedAnnotationAttributesWithImplicitAliasesInMetaAnnotationOnCo
351
351
Class <?> element = ComposedImplicitAliasesContextConfigClass .class ;
352
352
String name = ImplicitAliasesContextConfig .class .getName ();
353
353
AnnotationAttributes attributes = getMergedAnnotationAttributes (element , name );
354
- String [] expected = new String [] { "A.xml" , "B.xml" } ;
354
+ String [] expected = asArray ( "A.xml" , "B.xml" ) ;
355
355
356
356
assertNotNull ("Should find @ImplicitAliasesContextConfig on " + element .getSimpleName (), attributes );
357
357
assertArrayEquals ("groovyScripts" , expected , attributes .getStringArray ("groovyScripts" ));
@@ -403,7 +403,7 @@ public void getMergedAnnotationWithImplicitAliasesInMetaAnnotationOnComposedAnno
403
403
Class <?> element = ComposedImplicitAliasesContextConfigClass .class ;
404
404
String name = ImplicitAliasesContextConfig .class .getName ();
405
405
ImplicitAliasesContextConfig config = getMergedAnnotation (element , ImplicitAliasesContextConfig .class );
406
- String [] expected = new String [] { "A.xml" , "B.xml" } ;
406
+ String [] expected = asArray ( "A.xml" , "B.xml" ) ;
407
407
408
408
assertNotNull ("Should find @ImplicitAliasesContextConfig on " + element .getSimpleName (), config );
409
409
assertArrayEquals ("groovyScripts" , expected , config .groovyScripts ());
@@ -573,8 +573,8 @@ public void findMergedAnnotationWithAttributeAliasesInTargetAnnotation() {
573
573
574
574
@ Test
575
575
public void findMergedAnnotationForMultipleMetaAnnotationsWithClashingAttributeNames () {
576
- final String [] xmlLocations = new String [] { "test.xml" } ;
577
- final String [] propFiles = new String [] { "test.properties" } ;
576
+ final String [] xmlLocations = asArray ( "test.xml" ) ;
577
+ final String [] propFiles = asArray ( "test.properties" ) ;
578
578
579
579
Class <?> element = AliasedComposedContextConfigAndTestPropSourceClass .class ;
580
580
@@ -597,7 +597,7 @@ public void findMergedAnnotationForMultipleMetaAnnotationsWithClashingAttributeN
597
597
598
598
@ Test
599
599
public void findMergedAnnotationAttributesOnClassWithAttributeAliasInComposedAnnotationAndNestedAnnotationsInTargetAnnotation () {
600
- String [] expected = new String [] { "com.example.app.test" } ;
600
+ String [] expected = asArray ( "com.example.app.test" ) ;
601
601
Class <?> element = TestComponentScanClass .class ;
602
602
AnnotationAttributes attributes = findMergedAnnotationAttributes (element , ComponentScan .class );
603
603
assertNotNull ("Should find @ComponentScan on " + element , attributes );
@@ -617,7 +617,7 @@ public void findMergedAnnotationAttributesOnClassWithAttributeAliasInComposedAnn
617
617
*/
618
618
@ Test
619
619
public void findMergedAnnotationAttributesOnClassWithBothAttributesOfAnAliasPairDeclared () {
620
- String [] expected = new String [] { "com.example.app.test" } ;
620
+ String [] expected = asArray ( "com.example.app.test" ) ;
621
621
Class <?> element = ComponentScanWithBasePackagesAndValueAliasClass .class ;
622
622
AnnotationAttributes attributes = findMergedAnnotationAttributes (element , ComponentScan .class );
623
623
@@ -638,12 +638,17 @@ public void findMergedAnnotationWithLocalAliasesThatConflictWithAttributesInMeta
638
638
assertArrayEquals ("classes for " + element , new Class <?>[] { Number .class }, contextConfig .classes ());
639
639
}
640
640
641
+
641
642
private Set <String > names (Class <?>... classes ) {
642
643
return stream (classes ).map (Class ::getName ).collect (toSet ());
643
644
}
644
645
646
+ @ SafeVarargs
647
+ private static <T > T [] asArray (T ... arr ) {
648
+ return arr ;
649
+ }
645
650
646
- static AnnotationAttributes findMergedAnnotationAttributes (AnnotatedElement element , Class <? extends Annotation > annotationType ) {
651
+ private static AnnotationAttributes findMergedAnnotationAttributes (AnnotatedElement element , Class <? extends Annotation > annotationType ) {
647
652
Assert .notNull (annotationType , "annotationType must not be null" );
648
653
return AnnotatedElementUtils .findMergedAnnotationAttributes (element , annotationType .getName (), false , false );
649
654
}
0 commit comments