Skip to content

Commit 8e23d3c

Browse files
committed
Fix test and API use.
1 parent 55b0551 commit 8e23d3c

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/DynamicType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5933,8 +5933,8 @@ public RequiresDefinition<U> requiredVersion(@MaybeNull String version) {
59335933
@Override
59345934
protected ModuleDefinition<U> materialize() {
59355935
Map<String, ModuleDescription.Requires> requires = new LinkedHashMap<String, ModuleDescription.Requires>(ModuleDefinitionAdapter.this.requires);
5936-
requires.put(name, new ModuleDescription.Requires.Simple(version, modifiers));
5937-
return new ModuleDefinitionAdapter(ModuleDefinitionAdapter.this.name,
5936+
requires.put(module, new ModuleDescription.Requires.Simple(version, modifiers));
5937+
return new ModuleDefinitionAdapter(name,
59385938
ModuleDefinitionAdapter.this.modifiers,
59395939
ModuleDefinitionAdapter.this.version,
59405940
mainClass,

byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/subclass/SubclassDynamicTypeBuilderTest.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@
3131
import org.junit.Rule;
3232
import org.junit.Test;
3333
import org.junit.rules.MethodRule;
34+
import org.objectweb.asm.ClassReader;
3435
import 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;
3643
import java.lang.annotation.Annotation;
3744
import java.lang.annotation.ElementType;
3845
import 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

Comments
 (0)