Search in sources :

Example 81 with CtClass

use of javassist.CtClass in project javassist-maven-plugin by icon-Systemhaus-GmbH.

the class TestJavassistTransformerExecutor_transform method use_input_directory_if_output_directory_is_null.

@Test
public void use_input_directory_if_output_directory_is_null() throws Exception {
    // given
    final String className = oneTestClass();
    final CtClass candidateClass = stampedClass(className);
    // use input if output is not set
    candidateClass.writeFile(eq(classDirectory().getAbsolutePath()));
    configureClassPool(this.classPool).importPackage(className);
    expectLastCall();
    expect(this.classPool.get(className)).andReturn(candidateClass);
    expect(this.classTransformer.shouldTransform(same(candidateClass))).andReturn(true);
    this.classTransformer.applyTransformations(same(candidateClass));
    expectLastCall();
    replay(candidateClass, this.classPool, this.classTransformer);
    // when
    sut.transform(this.classTransformer, classDirectory().getAbsolutePath(), null);
    // then
    verify(candidateClass, this.classPool, this.classTransformer);
}
Also used : CtClass(javassist.CtClass) Test(org.junit.Test)

Example 82 with CtClass

use of javassist.CtClass in project javassist-maven-plugin by icon-Systemhaus-GmbH.

the class TestJavassistTransformerExecutor_transform method stampedClass.

private CtClass stampedClass(final String className) throws CannotCompileException, NotFoundException {
    final CtClass candidateClass = super.stampedClass(className, initializeClass(mock("candidateClass", CtClass.class)));
    expect(candidateClass.getNestedClasses()).andReturn(new CtClass[0]);
    return candidateClass;
}
Also used : CtClass(javassist.CtClass)

Example 83 with CtClass

use of javassist.CtClass in project javassist-maven-plugin by icon-Systemhaus-GmbH.

the class TestJavassistTransformerExecutor_transform method transform_stamp_and_write_class.

@Test
public void transform_stamp_and_write_class() throws Exception {
    // given
    final String className = oneTestClass();
    final Iterator<String> classNames = classNames(className);
    final CtClass candidateClass = stampedClass(className);
    candidateClass.writeFile(eq(transformedClassDirectory().getAbsolutePath()));
    configureClassPool(this.classPool).importPackage(className);
    expectLastCall();
    expect(this.classPool.get(className)).andReturn(candidateClass);
    expect(this.classTransformer.shouldTransform(same(candidateClass))).andReturn(true);
    this.classTransformer.applyTransformations(same(candidateClass));
    expectLastCall();
    replay(candidateClass, classNames, this.classPool, this.classTransformer);
    // when
    sut.transform(this.classTransformer, classDirectory().getAbsolutePath(), transformedClassDirectory().getAbsolutePath(), classNames);
    // then
    verify(candidateClass, classNames, this.classPool, this.classTransformer);
}
Also used : CtClass(javassist.CtClass) Test(org.junit.Test)

Example 84 with CtClass

use of javassist.CtClass in project javassist-maven-plugin by icon-Systemhaus-GmbH.

the class TestJavassistTransformerExecutor_transform_with_nested_classes method stampedClassWithNestedClasses.

private CtClass stampedClassWithNestedClasses(final String className, final CtClass... nestedClasses) throws CannotCompileException, NotFoundException, IOException {
    final CtClass candidateClass = super.stampedClass(className, initializeClass(mock("candidateClass", CtClass.class)));
    candidateClass.writeFile(eq(transformedClassDirectory().getAbsolutePath()));
    expect(candidateClass.getNestedClasses()).andReturn(nestedClasses);
    return candidateClass;
}
Also used : CtClass(javassist.CtClass)

Example 85 with CtClass

use of javassist.CtClass in project javassist-maven-plugin by icon-Systemhaus-GmbH.

the class TestJavassistTransformerExecutor_transform_with_nested_classes method do_nothing_if_nestedClass_is_stamped.

@Test
public void do_nothing_if_nestedClass_is_stamped() throws Exception {
    // given
    final String className = oneTestClass();
    final CtClass nestedClass = mock("nestedClass", CtClass.class);
    expect(nestedClass.isModified()).andReturn(true);
    expect(nestedClass.getDeclaredField(startsWith(STAMP_FIELD_NAME))).andReturn(mock("nestedClass_stampField", CtField.class));
    final Iterator<String> classNames = classNames(className);
    final CtClass candidateClass = configureCandidateClassFoTransformation(className, stampedClassWithNestedClasses(className, nestedClass));
    replay(nestedClass, candidateClass, classNames, this.classPool, this.classTransformer);
    // when
    executeTransform(classNames);
    // then
    verify(nestedClass, candidateClass, classNames, this.classPool, this.classTransformer);
}
Also used : CtClass(javassist.CtClass) CtField(javassist.CtField) Test(org.junit.Test)

Aggregations

CtClass (javassist.CtClass)271 CtMethod (javassist.CtMethod)96 ClassPool (javassist.ClassPool)93 NotFoundException (javassist.NotFoundException)85 Test (org.junit.Test)63 CannotCompileException (javassist.CannotCompileException)62 CtField (javassist.CtField)53 IOException (java.io.IOException)35 CtConstructor (javassist.CtConstructor)26 Method (java.lang.reflect.Method)17 LoaderClassPath (javassist.LoaderClassPath)16 ClassFile (javassist.bytecode.ClassFile)14 ArrayList (java.util.ArrayList)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)11 ConstPool (javassist.bytecode.ConstPool)11 File (java.io.File)8 FileNotFoundException (java.io.FileNotFoundException)8 Collectors (java.util.stream.Collectors)8 IllegalClassFormatException (java.lang.instrument.IllegalClassFormatException)7