|
33 | 33 | import org.objectweb.asm.Opcodes; |
34 | 34 |
|
35 | 35 | import java.lang.annotation.Annotation; |
| 36 | +import java.lang.annotation.ElementType; |
36 | 37 | import java.lang.annotation.Retention; |
37 | 38 | import java.lang.annotation.RetentionPolicy; |
| 39 | +import java.lang.annotation.Target; |
38 | 40 | import java.lang.reflect.AnnotatedElement; |
39 | 41 | import java.lang.reflect.Constructor; |
40 | 42 | import java.lang.reflect.Method; |
41 | 43 | import java.lang.reflect.Modifier; |
42 | 44 | import java.lang.reflect.Type; |
43 | 45 | import java.util.ArrayList; |
| 46 | +import java.util.Collections; |
44 | 47 | import java.util.List; |
45 | 48 | import java.util.Map; |
46 | 49 |
|
|
51 | 54 | import static org.hamcrest.CoreMatchers.is; |
52 | 55 | import static org.hamcrest.CoreMatchers.not; |
53 | 56 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 57 | +import static org.hamcrest.CoreMatchers.nullValue; |
54 | 58 | import static org.hamcrest.CoreMatchers.sameInstance; |
55 | 59 | import static org.hamcrest.MatcherAssert.assertThat; |
56 | 60 |
|
@@ -225,31 +229,57 @@ public void testPackageDefinition() throws Exception { |
225 | 229 | @Test |
226 | 230 | @JavaVersionRule.Enforce(9) |
227 | 231 | public void testModuleDefinition() throws Exception { |
| 232 | + DynamicType.Builder<? extends Annotation> builder = new ByteBuddy() |
| 233 | + .makeAnnotation() |
| 234 | + .name(BAR + "." + FOO + BAR) |
| 235 | + .annotateType(AnnotationDescription.Builder.ofType(Retention.class) |
| 236 | + .define("value", RetentionPolicy.RUNTIME) |
| 237 | + .build()) |
| 238 | + .annotateType(AnnotationDescription.Builder.ofType(Target.class) |
| 239 | + .defineEnumerationArray("value", ElementType.class, ElementType.valueOf("MODULE")) |
| 240 | + .build()); |
228 | 241 | Class<?> type = new ByteBuddy() |
229 | 242 | .subclass(Object.class) |
230 | 243 | .name(BAR + "." + QUX) |
231 | 244 | .make() |
232 | | - .include(new ByteBuddy() |
233 | | - .makeAnnotation() |
234 | | - .name(Foo.class.getName()) |
235 | | - .annotateType(AnnotationDescription.Builder.ofType(Retention.class) |
236 | | - .define("value", RetentionPolicy.RUNTIME) |
237 | | - .build()) |
238 | | - .make()) |
| 245 | + .include(builder.make()) |
239 | 246 | .include(new ByteBuddy() |
240 | 247 | .makeModule(FOO) |
241 | 248 | .version("1") |
| 249 | + .mainClass(BAR + "." + QUX) |
242 | 250 | .packages(BAR) |
243 | 251 | .export(BAR) |
244 | | - .annotateType(AnnotationDescription.Builder.ofType(Foo.class).build()) |
| 252 | + .open(BAR) |
| 253 | + .uses(Runnable.class) |
| 254 | + .provides(Runnable.class.getName(), BAR + "." + QUX) |
| 255 | + .annotateType(AnnotationDescription.Builder.ofType(builder.toTypeDescription()).build()) |
245 | 256 | .make()) |
246 | 257 | .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER) |
247 | | - .getLoaded(); // TODO: filter module-info |
| 258 | + .getLoaded(); |
248 | 259 | ModuleDescription moduleDescription = ModuleDescription.ForLoadedModule.of(Class.class.getMethod("getModule").invoke(type)); |
249 | | - assertThat(moduleDescription.getActualName(), is(ModuleDescription.MODULE_CLASS_NAME)); |
| 260 | + assertThat(moduleDescription.getActualName(), is(FOO)); |
250 | 261 | assertThat(moduleDescription.getModifiers(), is(ModifierContributor.EMPTY_MASK)); |
251 | | - assertThat(moduleDescription.getDeclaredAnnotations().size(), is(1)); |
252 | | - assertThat(moduleDescription.getDeclaredAnnotations().get(0).getAnnotationType().getName(), is(Foo.class.getName())); |
| 262 | + assertThat(moduleDescription.getVersion(), is("1")); |
| 263 | + assertThat(moduleDescription.getMainClass(), is(BAR + "." + QUX)); |
| 264 | + assertThat(moduleDescription.getRequires().size(), is(1)); |
| 265 | + assertThat(moduleDescription.getRequires().get("java.base"), notNullValue(ModuleDescription.Requires.class)); |
| 266 | + assertThat(moduleDescription.getRequires().get("java.base").getModifiers(), is(Opcodes.ACC_MANDATED)); |
| 267 | + assertThat(moduleDescription.getRequires().get("java.base").getVersion(), nullValue(String.class)); |
| 268 | + assertThat(moduleDescription.getExports().size(), is(1)); |
| 269 | + assertThat(moduleDescription.getExports().get(BAR), notNullValue(ModuleDescription.Exports.class)); |
| 270 | + assertThat(moduleDescription.getExports().get(BAR).getModifiers(), is(0)); |
| 271 | + assertThat(moduleDescription.getExports().get(BAR).getTargets().size(), is(0)); |
| 272 | + assertThat(moduleDescription.getOpens().size(), is(1)); |
| 273 | + assertThat(moduleDescription.getOpens().get(BAR), notNullValue(ModuleDescription.Opens.class)); |
| 274 | + assertThat(moduleDescription.getOpens().get(BAR).getModifiers(), is(0)); |
| 275 | + assertThat(moduleDescription.getOpens().get(BAR).getTargets().size(), is(0)); |
| 276 | + assertThat(moduleDescription.getUses().size(), is(1)); |
| 277 | + assertThat(moduleDescription.getUses().contains(Runnable.class.getName()), is(true)); |
| 278 | + assertThat(moduleDescription.getProvides().size(), is(1)); |
| 279 | + assertThat(moduleDescription.getProvides().get(Runnable.class.getName()), notNullValue(ModuleDescription.Provides.class)); |
| 280 | + assertThat(moduleDescription.getProvides().get(Runnable.class.getName()).getProviders(), is(Collections.singleton(BAR + "." + QUX))); |
| 281 | +// assertThat(moduleDescription.getDeclaredAnnotations().size(), is(1)); TODO: why are these missing? |
| 282 | +// assertThat(moduleDescription.getDeclaredAnnotations().get(0).getAnnotationType().getName(), is(BAR + "." + FOO + BAR)); |
253 | 283 | } |
254 | 284 |
|
255 | 285 | @Test |
|
0 commit comments