コード例 #1
0
  private void assertGetMergedAnnotation(Class<?> element, String... expected) {
    String name = ContextConfig.class.getName();
    ContextConfig contextConfig = getMergedAnnotation(element, ContextConfig.class);

    assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), contextConfig);
    assertArrayEquals("locations", expected, contextConfig.locations());
    assertArrayEquals("value", expected, contextConfig.value());
    assertArrayEquals("classes", new Class<?>[0], contextConfig.classes());

    // Verify contracts between utility methods:
    assertTrue(isAnnotated(element, name));
  }
コード例 #2
0
  @Test
  public void
      findMergedAnnotationWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
    final String[] EMPTY = new String[0];
    Class<?> element = SpringAppConfigClass.class;
    ContextConfig contextConfig = findMergedAnnotation(element, ContextConfig.class);

    assertNotNull("Should find @ContextConfig on " + element, contextConfig);
    assertArrayEquals("locations for " + element, EMPTY, contextConfig.locations());
    // 'value' in @SpringAppConfig should not override 'value' in @ContextConfig
    assertArrayEquals("value for " + element, EMPTY, contextConfig.value());
    assertArrayEquals(
        "classes for " + element, new Class<?>[] {Number.class}, contextConfig.classes());
  }
コード例 #3
0
  @Test
  public void findMergedAnnotationForMultipleMetaAnnotationsWithClashingAttributeNames() {
    String[] xmlLocations = asArray("test.xml");
    String[] propFiles = asArray("test.properties");

    Class<?> element = AliasedComposedContextConfigAndTestPropSourceClass.class;

    ContextConfig contextConfig = findMergedAnnotation(element, ContextConfig.class);
    assertNotNull("@ContextConfig on " + element, contextConfig);
    assertArrayEquals("locations", xmlLocations, contextConfig.locations());
    assertArrayEquals("value", xmlLocations, contextConfig.value());

    // Synthesized annotation
    TestPropSource testPropSource = AnnotationUtils.findAnnotation(element, TestPropSource.class);
    assertArrayEquals("locations", propFiles, testPropSource.locations());
    assertArrayEquals("value", propFiles, testPropSource.value());

    // Merged annotation
    testPropSource = findMergedAnnotation(element, TestPropSource.class);
    assertNotNull("@TestPropSource on " + element, testPropSource);
    assertArrayEquals("locations", propFiles, testPropSource.locations());
    assertArrayEquals("value", propFiles, testPropSource.value());
  }