Skip to content

Commit 4f3ea37

Browse files
author
Rafael Winterhalter
committed
Added additional tests for loaded annotation handling.
1 parent 222a8fd commit 4f3ea37

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AnnotationDescriptionForLoadedAnnotationTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.lang.annotation.Retention;
88
import java.lang.annotation.RetentionPolicy;
99
import java.lang.reflect.Method;
10+
import java.net.URL;
11+
import java.net.URLClassLoader;
1012

1113
import static org.hamcrest.CoreMatchers.is;
1214
import static org.hamcrest.MatcherAssert.assertThat;
@@ -41,6 +43,17 @@ public void testInoperational() throws Exception {
4143
.getValue(new MethodDescription.ForLoadedMethod(PrivateAnnotation.class.getDeclaredMethod("value")));
4244
}
4345

46+
@Test(expected = IllegalArgumentException.class)
47+
public void testLoadAnnotationWrongClassLoader() throws Exception {
48+
describe(Carrier.class.getAnnotation(PrivateAnnotation.class), Carrier.class).prepare(PrivateAnnotation.class).load(null);
49+
}
50+
51+
@Test
52+
public void testLoadAnnotationSubClassLoader() throws Exception {
53+
assertThat(describe(Carrier.class.getAnnotation(PrivateAnnotation.class), Carrier.class).prepare(PrivateAnnotation.class)
54+
.load(new URLClassLoader(new URL[0], getClass().getClassLoader())), is(Carrier.class.getAnnotation(PrivateAnnotation.class)));
55+
}
56+
4457
@Retention(RetentionPolicy.RUNTIME)
4558
private @interface PrivateAnnotation {
4659

0 commit comments

Comments
 (0)