Test for expected behavior of getAllMergedAnnotations vs findAllMergedAnnotations

Issue: SPR-15271
(cherry picked from commit 6108ab1)
This commit is contained in:
Juergen Hoeller
2017-02-22 15:28:34 +01:00
parent 1db42081e5
commit e5010a823b

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,8 +36,7 @@ import org.junit.Test;
import org.junit.internal.ArrayComparisonFailure;
import org.junit.rules.ExpectedException;
import org.springframework.core.annotation.AnnotationUtilsTests.WebController;
import org.springframework.core.annotation.AnnotationUtilsTests.WebMapping;
import org.springframework.core.annotation.AnnotationUtilsTests.*;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
@@ -54,6 +53,7 @@ import static org.springframework.core.annotation.AnnotationUtilsTests.*;
*
* @author Sam Brannen
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 4.0.3
* @see AnnotationUtilsTests
* @see MultipleComposedAnnotationsOnSingleAnnotatedElementTests
@@ -91,6 +91,10 @@ public class AnnotatedElementUtilsTests {
assertEquals(names(TransactionalComponent.class, Transactional.class, Component.class), names);
}
private Set<String> names(Class<?>... classes) {
return stream(classes).map(Class::getName).collect(toSet());
}
@Test
public void hasMetaAnnotationTypesOnNonAnnotatedClass() {
assertFalse(hasMetaAnnotationTypes(NonAnnotatedClass.class, TX_NAME));
@@ -715,8 +719,18 @@ public class AnnotatedElementUtilsTests {
assertEquals(SpringAppConfigClass.class.getAnnotation(Resource.class), findMergedAnnotation(SpringAppConfigClass.class, Resource.class));
}
private Set<String> names(Class<?>... classes) {
return stream(classes).map(Class::getName).collect(toSet());
@Test
public void getAllMergedAnnotationsOnClassWithInterface() throws Exception {
Method m = TransactionalServiceImpl.class.getMethod("doIt");
Set<Transactional> allMergedAnnotations = getAllMergedAnnotations(m, Transactional.class);
assertTrue(allMergedAnnotations.isEmpty());
}
@Test
public void findAllMergedAnnotationsOnClassWithInterface() throws Exception {
Method m = TransactionalServiceImpl.class.getMethod("doIt");
Set<Transactional> allMergedAnnotations = findAllMergedAnnotations(m, Transactional.class);
assertEquals(1, allMergedAnnotations.size());
}
@@ -1271,4 +1285,17 @@ public class AnnotatedElementUtilsTests {
static class ResourceHolder {
}
interface TransactionalService {
@Transactional
void doIt();
}
class TransactionalServiceImpl implements TransactionalService {
@Override
public void doIt() {
}
}
}