Search in sources :

Example 11 with ClassFileLocator

use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.

the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericResolutionIsLazyForSimpleCreation.

@Test
public void testGenericResolutionIsLazyForSimpleCreation() throws Exception {
    ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
    new ByteBuddy().with(TypeValidation.DISABLED).with(MethodGraph.Empty.INSTANCE).with(InstrumentedType.Factory.Default.FROZEN).redefine(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()), classFileLocator).make();
    verify(classFileLocator, times(2)).locate(GenericType.class.getName());
    verifyNoMoreInteractions(classFileLocator);
}
Also used : ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) ByteBuddy(net.bytebuddy.ByteBuddy) Test(org.junit.Test) AbstractTypeDescriptionTest(net.bytebuddy.description.type.AbstractTypeDescriptionTest)

Example 12 with ClassFileLocator

use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.

the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericSuperInterfaceNavigatedHierarchyResolutionIsLazy.

@Test
public void testGenericSuperInterfaceNavigatedHierarchyResolutionIsLazy() throws Exception {
    ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
    assertThat(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()).getInterfaces().getOnly().getInterfaces().getOnly().asErasure(), CoreMatchers.is((TypeDescription) new TypeDescription.ForLoadedType(SuperInterface.class)));
    verify(classFileLocator).locate(GenericType.class.getName());
    verify(classFileLocator).locate(SampleGenericInterface.class.getName());
    verifyNoMoreInteractions(classFileLocator);
}
Also used : ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test) AbstractTypeDescriptionTest(net.bytebuddy.description.type.AbstractTypeDescriptionTest)

Example 13 with ClassFileLocator

use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.

the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testReferencedTypeIsCached.

@Test
public void testReferencedTypeIsCached() throws Exception {
    ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
    TypePool typePool = TypePool.Default.WithLazyResolution.of(classFileLocator);
    TypePool.Resolution resolution = typePool.describe(String.class.getName());
    assertThat(resolution.resolve().getModifiers(), CoreMatchers.is(TypeDescription.STRING.getModifiers()));
    TypeDescription superClass = resolution.resolve().getSuperClass().asErasure();
    assertThat(superClass, CoreMatchers.is(TypeDescription.OBJECT));
    assertThat(superClass.getModifiers(), CoreMatchers.is(TypeDescription.OBJECT.getModifiers()));
    assertThat(superClass.getInterfaces(), CoreMatchers.is(TypeDescription.OBJECT.getInterfaces()));
    assertThat(typePool.describe(String.class.getName()).resolve(), CoreMatchers.is(resolution.resolve()));
    verify(classFileLocator).locate(String.class.getName());
    verify(classFileLocator).locate(Object.class.getName());
    verifyNoMoreInteractions(classFileLocator);
}
Also used : ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test) AbstractTypeDescriptionTest(net.bytebuddy.description.type.AbstractTypeDescriptionTest)

Example 14 with ClassFileLocator

use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.

the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testTypeIsLazy.

@Test
public void testTypeIsLazy() throws Exception {
    ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
    TypePool typePool = TypePool.Default.WithLazyResolution.of(classFileLocator);
    TypePool.Resolution resolution = typePool.describe(Object.class.getName());
    assertThat(resolution.resolve().getName(), CoreMatchers.is(TypeDescription.OBJECT.getName()));
    verifyZeroInteractions(classFileLocator);
}
Also used : ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) Test(org.junit.Test) AbstractTypeDescriptionTest(net.bytebuddy.description.type.AbstractTypeDescriptionTest)

Example 15 with ClassFileLocator

use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.

the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testNonGenericResolutionIsLazyForSimpleCreationNonFrozen.

@Test
public void testNonGenericResolutionIsLazyForSimpleCreationNonFrozen() throws Exception {
    ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
    new ByteBuddy().with(TypeValidation.DISABLED).with(MethodGraph.Empty.INSTANCE).with(InstrumentedType.Factory.Default.MODIFIABLE).redefine(describe(NonGenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()), classFileLocator).make();
    verify(classFileLocator, times(2)).locate(NonGenericType.class.getName());
    verifyNoMoreInteractions(classFileLocator);
}
Also used : ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) ByteBuddy(net.bytebuddy.ByteBuddy) Test(org.junit.Test) AbstractTypeDescriptionTest(net.bytebuddy.description.type.AbstractTypeDescriptionTest)

Aggregations

ClassFileLocator (net.bytebuddy.dynamic.ClassFileLocator)31 Test (org.junit.Test)29 TypeDescription (net.bytebuddy.description.type.TypeDescription)17 AbstractTypeDescriptionTest (net.bytebuddy.description.type.AbstractTypeDescriptionTest)15 List (java.util.List)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 ByteBuddy (net.bytebuddy.ByteBuddy)6 File (java.io.File)2 Instrumentation (java.lang.instrument.Instrumentation)2 ArrayList (java.util.ArrayList)2 TypePool (net.bytebuddy.pool.TypePool)2 IOException (java.io.IOException)1 ClassDefinition (java.lang.instrument.ClassDefinition)1 Callable (java.util.concurrent.Callable)1 RandomString (net.bytebuddy.utility.RandomString)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 GradleException (org.gradle.api.GradleException)1 BaseMatcher (org.hamcrest.BaseMatcher)1 Description (org.hamcrest.Description)1