1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| @IfProfileValue(name = "test-user", value = "development")
@IntegrationTest(users = { "abc", "def" })
public class Test {
enum EnumAnnotationPolicy {
EXCLUSIVE, OVERRIDES, IGNORE
};
Test() {
boolean integrationTestAnnotationContainsIfProfileAnnotation = contains(
IntegrationTest.class, IfProfileValue.class);
IntegrationTest a = getClass().getAnnotation(IntegrationTest.class);
if (a != null) {
System.out.println("a.profile=" + a.profile());
System.out.println("a.users=" + Arrays.toString(a.users()));
}
IfProfileValue b = getClass().getAnnotation(IfProfileValue.class);
if (b != null) {
System.out.println("b.name=" + b.name());
System.out.println("b.value=" + b.value());
}
if (a != null && b != null
&& integrationTestAnnotationContainsIfProfileAnnotation) {
for (EnumAnnotationPolicy policy : EnumAnnotationPolicy.values()) {
switch (policy) {
case EXCLUSIVE:
System.out.println("Les annotations "
+ IntegrationTest.class.getSimpleName() + " et "
+ IfProfileValue.class.getSimpleName()
+ " sont mutuellement exclusives");
break;
case OVERRIDES:
System.out.println("L'annotation "
+ IntegrationTest.class.getSimpleName()
+ " est overridee par l'annotation "
+ IfProfileValue.class.getSimpleName());
break;
case IGNORE:
System.out.println("L'annotation "
+ IfProfileValue.class.getSimpleName()
+ " est ignoree au profit de l'annotation "
+ IntegrationTest.class.getSimpleName());
break;
}
}
}
}
private static boolean contains(Class<? extends Annotation> container,
Class<? extends Annotation> content) {
boolean contains = false;
for (Method method : container.getDeclaredMethods()) {
if (method.getReturnType() == content) {
System.out.println("L'annotation " + container.getSimpleName()
+ " contient la méthode '" + method.getName()
+ "' renvoyant une annotation " + content.getSimpleName());
contains = true;
break;
}
}
return contains;
}
public static void main(String[] args) {
new Test();
}
} |
Partager