3131import org .junit .Rule ;
3232import org .junit .Test ;
3333import org .junit .rules .MethodRule ;
34+ import org .objectweb .asm .ClassReader ;
3435import org .objectweb .asm .Opcodes ;
36+ import org .objectweb .asm .util .ASMifier ;
37+ import org .objectweb .asm .util .Textifier ;
38+ import org .objectweb .asm .util .TraceClassVisitor ;
3539
40+ import java .io .File ;
41+ import java .io .FileInputStream ;
42+ import java .io .PrintWriter ;
3643import java .lang .annotation .Annotation ;
3744import java .lang .annotation .ElementType ;
3845import java .lang .annotation .Retention ;
@@ -230,42 +237,35 @@ public void testPackageDefinition() throws Exception {
230237 @ Test
231238 @ JavaVersionRule .Enforce (9 )
232239 public void testModuleDefinition () throws Exception {
233- DynamicType .Builder <? extends Annotation > builder = new ByteBuddy ()
234- .makeAnnotation ()
235- .name (BAR + "." + FOO + BAR )
236- .annotateType (AnnotationDescription .Builder .ofType (Retention .class )
237- .define ("value" , RetentionPolicy .RUNTIME )
238- .build ())
239- .annotateType (AnnotationDescription .Builder .ofType (Target .class )
240- .defineEnumerationArray ("value" , ElementType .class , ElementType .valueOf ("MODULE" ))
241- .build ());
242240 Class <?> type = new ByteBuddy ()
243241 .subclass (Object .class )
244242 .name (BAR + "." + QUX )
245243 .make ()
246- .include (builder .make ())
247244 .include (new ByteBuddy ()
248245 .makeModule (FOO )
249246 .version ("1" )
250247 .mainClass (BAR + "." + QUX )
251248 .packages (BAR )
249+ .require ("java.instrument" )
252250 .export (BAR )
253251 .open (BAR )
254252 .uses (Runnable .class )
255253 .provides (Runnable .class .getName (), BAR + "." + QUX )
256- .annotateType (AnnotationDescription .Builder .ofType (builder .toTypeDescription ()).build ())
257254 .make ())
258- .load (ClassLoadingStrategy .BOOTSTRAP_LOADER , ClassLoadingStrategy .Default .WRAPPER .with (ModuleLayerFromSingleClassLoaderDecorator .Factory .INSTANCE ))
255+ .load (ClassLoadingStrategy .Default . BOOTSTRAP_LOADER , ClassLoadingStrategy .Default .WRAPPER .with (ModuleLayerFromSingleClassLoaderDecorator .Factory .INSTANCE ))
259256 .getLoaded ();
260257 ModuleDescription moduleDescription = ModuleDescription .ForLoadedModule .of (Class .class .getMethod ("getModule" ).invoke (type ));
261258 assertThat (moduleDescription .getActualName (), is (FOO ));
262259 assertThat (moduleDescription .getModifiers (), is (ModifierContributor .EMPTY_MASK ));
263260 assertThat (moduleDescription .getVersion (), is ("1" ));
264261 assertThat (moduleDescription .getMainClass (), is (BAR + "." + QUX ));
265- assertThat (moduleDescription .getRequires ().size (), is (1 ));
262+ assertThat (moduleDescription .getRequires ().size (), is (2 ));
266263 assertThat (moduleDescription .getRequires ().get ("java.base" ), notNullValue (ModuleDescription .Requires .class ));
267264 assertThat (moduleDescription .getRequires ().get ("java.base" ).getModifiers (), is (Opcodes .ACC_MANDATED ));
268265 assertThat (moduleDescription .getRequires ().get ("java.base" ).getVersion (), nullValue (String .class ));
266+ assertThat (moduleDescription .getRequires ().get ("java.instrument" ), notNullValue (ModuleDescription .Requires .class ));
267+ assertThat (moduleDescription .getRequires ().get ("java.instrument" ).getModifiers (), is (0 ));
268+ assertThat (moduleDescription .getRequires ().get ("java.instrument" ).getVersion (), nullValue (String .class ));
269269 assertThat (moduleDescription .getExports ().size (), is (1 ));
270270 assertThat (moduleDescription .getExports ().get (BAR ), notNullValue (ModuleDescription .Exports .class ));
271271 assertThat (moduleDescription .getExports ().get (BAR ).getModifiers (), is (0 ));
@@ -279,8 +279,6 @@ public void testModuleDefinition() throws Exception {
279279 assertThat (moduleDescription .getProvides ().size (), is (1 ));
280280 assertThat (moduleDescription .getProvides ().get (Runnable .class .getName ()), notNullValue (ModuleDescription .Provides .class ));
281281 assertThat (moduleDescription .getProvides ().get (Runnable .class .getName ()).getProviders (), is (Collections .singleton (BAR + "." + QUX )));
282- // assertThat(moduleDescription.getDeclaredAnnotations().size(), is(1)); TODO: why are these missing?
283- // assertThat(moduleDescription.getDeclaredAnnotations().get(0).getAnnotationType().getName(), is(BAR + "." + FOO + BAR));
284282 }
285283
286284 @ Test
0 commit comments