use of javassist.build.IClassTransformer in project javassist-maven-plugin by icon-Systemhaus-GmbH.
the class TestJavassistTransformerExecutor_TransformerClasses_handling method applyTransformation_if_shouldTransform_returns_true_and_class_has_no_stamp.
@Test
public void applyTransformation_if_shouldTransform_returns_true_and_class_has_no_stamp() throws Exception {
// given
final String className = oneTestClass();
final Capture<CtClass> classCapture_shouldTransform = newInstance();
final Capture<CtClass> classCapture_applyTransformations = newInstance();
final IClassTransformer mockTransformer = createMock("mockTransformer", IClassTransformer.class);
expect(mockTransformer.shouldTransform(capture(classCapture_shouldTransform))).andReturn(true);
mockTransformer.applyTransformations(capture(classCapture_applyTransformations));
expectLastCall().times(1);
replay(mockTransformer);
sut.setTransformerClasses(mockTransformer);
// when
sut.execute();
// then
verify(mockTransformer);
assertEquals(className, classCapture_shouldTransform.getValue().getName());
assertEquals(className, classCapture_applyTransformations.getValue().getName());
}
use of javassist.build.IClassTransformer in project javassist-maven-plugin by icon-Systemhaus-GmbH.
the class JavassistMojo method instantiateTransformerClasses.
/**
* Instantiates and configures the passed transformer classes.
*
* @param contextClassLoader maybe {@code null}
* @param transformerClasses maybe {@code null}
* @return array of passed transformer class name instances and never {@code null} but maybe
* empty.
* @throws Exception by
* {@link #instantiateTransformerClass(ClassLoader, ClassTransformerConfiguration)} and
* {@link #configureTransformerInstance(IClassTransformer, Properties)}
* @see #instantiateTransformerClass(ClassLoader, ClassTransformerConfiguration)
* @see #configureTransformerInstance(IClassTransformer, Properties)
*/
// @formatter:off
protected IClassTransformer[] instantiateTransformerClasses(final ClassLoader contextClassLoader, final ClassTransformerConfiguration... transformerClasses) throws Exception {
// @formatter:on
if (null == transformerClasses || transformerClasses.length <= 0) {
throw new MojoExecutionException("Invalid transformer classes passed");
}
final List<IClassTransformer> transformerInstances = new LinkedList<IClassTransformer>();
for (ClassTransformerConfiguration transformerClass : transformerClasses) {
final IClassTransformer transformerInstance = instantiateTransformerClass(contextClassLoader, transformerClass);
configureTransformerInstance(transformerInstance, transformerClass.getProperties());
transformerInstances.add(transformerInstance);
}
return transformerInstances.toArray(new IClassTransformer[transformerInstances.size()]);
}
use of javassist.build.IClassTransformer in project javassist-maven-plugin by icon-Systemhaus-GmbH.
the class TestJavassistTransformerExecutor_TransformerClasses_handling method not_applyTransformation_if_shouldTransform_returns_false.
@Test
public void not_applyTransformation_if_shouldTransform_returns_false() throws Exception {
// given
final String className = oneTestClass();
final Capture<CtClass> classCapture_shouldTransform = newInstance();
final IClassTransformer mockTransformer = createMock("mockTransformer", IClassTransformer.class);
expect(mockTransformer.shouldTransform(capture(classCapture_shouldTransform))).andReturn(false);
replay(mockTransformer);
sut.setTransformerClasses(mockTransformer);
// when
sut.execute();
// then
verify(mockTransformer);
assertEquals(className, classCapture_shouldTransform.getValue().getName());
}
Aggregations