use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class TypeWriterDefaultTest method testTypeInLegacyConstantPoolRemapped.
@Test
public void testTypeInLegacyConstantPoolRemapped() throws Exception {
Class<?> dynamicType = new ByteBuddy(ClassFileVersion.JAVA_V4).with(TypeValidation.DISABLED).subclass(Object.class).defineMethod(FOO, Object.class, Visibility.PUBLIC).intercept(FixedValue.value(Object.class)).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(dynamicType.getDeclaredMethod(FOO).invoke(dynamicType.getDeclaredConstructor().newInstance()), is((Object) Object.class));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class TypeWriterDefaultTest method testLegacyTypeRedefinitionIsDiscovered.
@Test
public void testLegacyTypeRedefinitionIsDiscovered() throws Exception {
Class<?> dynamicType = new ByteBuddy().with(TypeValidation.DISABLED).redefine(Class.forName("net.bytebuddy.test.precompiled.TypeConstantSample")).method(named(BAR)).intercept(FixedValue.value(int.class)).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(dynamicType.getDeclaredMethod(BAR).invoke(null), is((Object) int.class));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class TypeWriterDefaultTest method testPrimitiveTypeInLegacyConstantPoolRemapped.
@Test
public void testPrimitiveTypeInLegacyConstantPoolRemapped() throws Exception {
Class<?> dynamicType = new ByteBuddy(ClassFileVersion.JAVA_V4).with(TypeValidation.DISABLED).subclass(Object.class).defineMethod(FOO, Object.class, Visibility.PUBLIC).intercept(FixedValue.value(int.class)).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(dynamicType.getDeclaredMethod(FOO).invoke(dynamicType.getDeclaredConstructor().newInstance()), is((Object) int.class));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class SubclassDynamicTypeBuilderTest method testDoesNotOverrideMethodWithPackagePrivateArgumentType.
@Test
public void testDoesNotOverrideMethodWithPackagePrivateArgumentType() throws Exception {
Class<?> type = new ByteBuddy().subclass(PackagePrivateArgumentType.class).name("net.bytebuddy.test.generated." + FOO).method(isDeclaredBy(PackagePrivateArgumentType.class)).intercept(StubMethod.INSTANCE).make().load(new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(PackagePrivateArgumentType.class, PackagePrivateArgumentType.Argument.class)), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethods().length, is(0));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class SubclassDynamicTypeBuilderTest method testParameterMetaDataSubclassForLoaded.
@Test
@JavaVersionRule.Enforce(8)
public void testParameterMetaDataSubclassForLoaded() throws Exception {
Class<?> dynamicType = new ByteBuddy().subclass(Class.forName(PARAMETER_NAME_CLASS)).method(named(FOO)).intercept(StubMethod.INSTANCE).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(dynamicType.getDeclaredMethods().length, is(1));
Class<?> executable = Class.forName("java.lang.reflect.Executable");
Method getParameters = executable.getDeclaredMethod("getParameters");
Class<?> parameter = Class.forName("java.lang.reflect.Parameter");
Method getName = parameter.getDeclaredMethod("getName");
Method getModifiers = parameter.getDeclaredMethod("getModifiers");
Method first = dynamicType.getDeclaredMethod("foo", String.class, long.class, int.class);
Object[] methodParameter = (Object[]) getParameters.invoke(first);
assertThat(getName.invoke(methodParameter[0]), is((Object) "first"));
assertThat(getName.invoke(methodParameter[1]), is((Object) "second"));
assertThat(getName.invoke(methodParameter[2]), is((Object) "third"));
assertThat(getModifiers.invoke(methodParameter[0]), is((Object) Opcodes.ACC_FINAL));
assertThat(getModifiers.invoke(methodParameter[1]), is((Object) 0));
assertThat(getModifiers.invoke(methodParameter[2]), is((Object) 0));
}
Aggregations