mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
Test complicated annotation constructs
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
e1d91f153b
commit
0681531dc0
@ -4,6 +4,7 @@ import java.lang.reflect.Proxy;
|
||||
|
||||
import avian.testing.annotations.Color;
|
||||
import avian.testing.annotations.Test;
|
||||
import avian.testing.annotations.TestComplex;
|
||||
import avian.testing.annotations.TestEnum;
|
||||
import avian.testing.annotations.TestInteger;
|
||||
|
||||
@ -30,6 +31,7 @@ public class Annotations {
|
||||
expect(noAnno.getAnnotation(Test.class) == null);
|
||||
expect(noAnno.getAnnotations().length == 0);
|
||||
testProxyDefaultValue();
|
||||
testComplexAnnotation();
|
||||
}
|
||||
|
||||
@Test("couscous")
|
||||
@ -54,4 +56,34 @@ public class Annotations {
|
||||
Proxy.newProxyInstance(loader, new Class[] { Test.class }, handler);
|
||||
expect("Hello, world!".equals(test.value()));
|
||||
}
|
||||
|
||||
private interface World {
|
||||
@TestComplex(arrayValue = { @Test, @Test(value = "7/9") },
|
||||
stringValue = "adjunct element", charValue = '7', doubleValue = 0.7778,
|
||||
classValue = TestInteger.class)
|
||||
int hello();
|
||||
}
|
||||
|
||||
private static void testComplexAnnotation(TestComplex annotation)
|
||||
throws Exception
|
||||
{
|
||||
expect(2 == annotation.arrayValue().length);
|
||||
expect("Hello, world!".equals(annotation.arrayValue()[0].value()));
|
||||
expect("7/9".equals(annotation.arrayValue()[1].value()));
|
||||
expect("adjunct element".equals(annotation.stringValue()));
|
||||
expect('7' == annotation.charValue());
|
||||
expect(0.7778 == annotation.doubleValue());
|
||||
expect(TestInteger.class == annotation.classValue());
|
||||
}
|
||||
|
||||
public static void testComplexAnnotation() throws Exception {
|
||||
ClassLoader loader = Annotations.class.getClassLoader();
|
||||
TestComplex annotation = (TestComplex)
|
||||
World.class.getMethod("hello").getAnnotation(TestComplex.class);
|
||||
testComplexAnnotation(annotation);
|
||||
Class clazz = Proxy.getProxyClass(loader, new Class[] { World.class });
|
||||
annotation = (TestComplex)
|
||||
clazz.getMethod("hello").getAnnotation(TestComplex.class);
|
||||
expect(annotation == null);
|
||||
}
|
||||
}
|
||||
|
14
test/avian/testing/annotations/TestComplex.java
Normal file
14
test/avian/testing/annotations/TestComplex.java
Normal file
@ -0,0 +1,14 @@
|
||||
package avian.testing.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TestComplex {
|
||||
public Test[] arrayValue();
|
||||
public Class classValue();
|
||||
public String stringValue();
|
||||
public char charValue();
|
||||
public double doubleValue();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user