use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader 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 net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class SubclassDynamicTypeBuilderTest method testDoesNotOverrideMethodWithPackagePrivateReturnType.
@Test
public void testDoesNotOverrideMethodWithPackagePrivateReturnType() throws Exception {
Class<?> type = new ByteBuddy().subclass(PackagePrivateReturnType.class).name("net.bytebuddy.test.generated." + FOO).method(isDeclaredBy(PackagePrivateReturnType.class)).intercept(StubMethod.INSTANCE).make().load(new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(PackagePrivateReturnType.class, PackagePrivateReturnType.Argument.class)), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethods().length, is(0));
}
use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class AnnotationDescriptionForLoadedAnnotationDifferentClassLoaderTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(Sample.class, SampleDefault.class, Other.class, SampleEnumeration.class, ExplicitTarget.class));
}
use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class AbstractDynamicTypeBuilderTest method testPreparedField.
@Test
public void testPreparedField() throws Exception {
ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(SampleAnnotation.class));
Class<?> type = createPlain().defineMethod(BAR, String.class, Visibility.PUBLIC).intercept(new PreparedField()).make().load(classLoader, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredFields().length, is(1));
assertThat(type.getDeclaredField(FOO).getName(), is(FOO));
assertThat(type.getDeclaredField(FOO).getType(), CoreMatchers.<Class<?>>is(Object.class));
assertThat(type.getDeclaredField(FOO).getModifiers(), is(MODIFIERS));
assertThat(type.getDeclaredField(FOO).getAnnotations().length, is(1));
Annotation annotation = type.getDeclaredField(FOO).getAnnotations()[0];
assertThat(annotation.annotationType().getName(), is(SampleAnnotation.class.getName()));
Method foo = annotation.annotationType().getDeclaredMethod(FOO);
assertThat(foo.invoke(annotation), is((Object) BAR));
}
use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class AbstractDynamicTypeBuilderTest method testTypeInitializer.
@Test
public void testTypeInitializer() throws Exception {
ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(Bar.class));
Class<?> type = createPlain().invokable(isTypeInitializer()).intercept(MethodCall.invoke(Bar.class.getDeclaredMethod("invoke"))).make().load(classLoader, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredConstructor().newInstance(), notNullValue(Object.class));
Class<?> foo = classLoader.loadClass(Bar.class.getName());
assertThat(foo.getDeclaredField(FOO).get(null), is((Object) FOO));
}
Aggregations