use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TransformerForMethodTest method testNoChangesUnlessSpecified.
@Test
public void testNoChangesUnlessSpecified() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
MethodDescription methodDescription = typeDescription.getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly();
MethodDescription transformed = Transformer.ForMethod.withModifiers().transform(typeDescription, methodDescription);
assertThat(transformed, is(methodDescription));
assertThat(transformed.getModifiers(), is(methodDescription.getModifiers()));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TransformerForMethodTest method testRetainsInstrumentedType.
@Test
public void testRetainsInstrumentedType() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
MethodDescription methodDescription = typeDescription.getSuperClass().getDeclaredMethods().filter(named(BAR)).getOnly();
MethodDescription transformed = Transformer.ForMethod.withModifiers().transform(typeDescription, methodDescription);
assertThat(transformed, is(methodDescription));
assertThat(transformed.getModifiers(), is(methodDescription.getModifiers()));
assertThat(transformed.getReturnType().asErasure(), is(typeDescription));
assertThat(transformed.getReturnType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
assertThat(transformed.getReturnType().getTypeArguments().size(), is(1));
assertThat(transformed.getReturnType().getTypeArguments().getOnly(), is(typeDescription.getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly().getReturnType()));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class InjectionClassLoaderTest method testInjection.
@Test
@SuppressWarnings("unchecked")
public void testInjection() throws Exception {
InjectionClassLoader classLoader = mock(InjectionClassLoader.class);
TypeDescription typeDescription = mock(TypeDescription.class);
byte[] binaryRepresentation = new byte[0];
when(typeDescription.getName()).thenReturn(FOO);
when(classLoader.defineClass(FOO, binaryRepresentation)).thenReturn((Class) Object.class);
assertThat(InjectionClassLoader.Strategy.INSTANCE.load(classLoader, Collections.singletonMap(typeDescription, binaryRepresentation)), is(Collections.<TypeDescription, Class<?>>singletonMap(typeDescription, Object.class)));
verify(classLoader).defineClass(FOO, binaryRepresentation);
verifyNoMoreInteractions(classLoader);
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class ClassFileLocatorSimpleTest method testDynamicType.
@Test
public void testDynamicType() throws Exception {
DynamicType dynamicType = mock(DynamicType.class);
TypeDescription typeDescription = mock(TypeDescription.class);
when(typeDescription.getName()).thenReturn(FOO);
when(dynamicType.getAllTypes()).thenReturn(Collections.singletonMap(typeDescription, QUX));
ClassFileLocator classFileLocator = ClassFileLocator.Simple.of(dynamicType);
assertThat(classFileLocator.locate(FOO).isResolved(), is(true));
assertThat(classFileLocator.locate(FOO).resolve(), is(QUX));
assertThat(classFileLocator.locate(BAR).isResolved(), is(false));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class AgentBuilderDescriptionStrategyTest method testDescriptionHybridWithoutLoaded.
@Test
public void testDescriptionHybridWithoutLoaded() throws Exception {
when(typePool.describe(Object.class.getName())).thenReturn(new TypePool.Resolution.Simple(typeDescription));
TypeDescription typeDescription = AgentBuilder.DescriptionStrategy.Default.HYBRID.apply(Object.class.getName(), null, typePool, mock(AgentBuilder.CircularityLock.class), Object.class.getClassLoader(), JavaModule.ofType(Object.class));
assertThat(typeDescription, is(this.typeDescription));
}
Aggregations