MimicProcessor extends ClassTransformer { @Override protected void applyTransformations(final CtClass classToTransform) throws ClassNotFoundException, NotFoundException, CannotCompileException, MimicException { getLogger().debug("Analysing " + classToTransform); Mimic mimicAnnnotation = (Mimic) classToTransform .getAnnotation(Mimic.class); Class<?> srcClass = mimicAnnnotation.sourceClass(); MimicMode defaultMimicMode = mimicAnnnotation.defaultMimicMode(); MimicMethod[] mimicMethods = mimicAnnnotation.mimicMethods(); CtClass src = ClassPool.getDefault().get(srcClass.getName()); if (mimicAnnnotation.isMimicingInterfaces() && mimicAnnnotation.isMimicingFields() && mimicAnnnotation.isMimicingConstructors() && mimicAnnnotation.isMimicingMethods()) { mimic.mimicClass(src, classToTransform, defaultMimicMode, mimicMethods); } else { if (mimicAnnnotation.isMimicingInterfaces()) { mimic.mimicInterfaces(src, classToTransform); } if (mimicAnnnotation.isMimicingFields()) { mimic.mimicFields(src, classToTransform); } if (mimicAnnnotation.isMimicingConstructors()) { mimic.mimicConstructors(src, classToTransform); } if (mimicAnnnotation.isMimicingMethods()) { mimic.mimicMethods(src, classToTransform, defaultMimicMode, mimicMethods); } } getLogger().debug( "Class " + classToTransform.getName() + " now mimics " + src.getName()); } MimicProcessor();   }
@Test public void testTransform_with_mimic_constructors_only() throws Exception { addMimicAnnotation(dst, TestSourceClass.class.getName(), false, false, true, false); final MimicCreator mimicMock = EasyMock.createMock(MimicCreator.class); Guice.createInjector(new MimicCreatorTestModule(mimicMock)) .injectMembers(mimicProcessor); mimicMock.mimicConstructors( EasyMock.eq(ClassPool.getDefault().get( TestSourceClass.class.getName())), EasyMock.eq(dst)); EasyMock.replay(mimicMock); mimicProcessor.applyTransformations(dst); EasyMock.verify(mimicMock); }
@Test public void testTransform_with_mimic_defaults() throws Exception { addMimicAnnotation(dst, TestSourceClass.class.getName(), true, true, true, true); final MimicCreator mimicMock = EasyMock.createMock(MimicCreator.class); Guice.createInjector(new MimicCreatorTestModule(mimicMock)) .injectMembers(mimicProcessor); mimicMock.mimicClass( EasyMock.eq(ClassPool.getDefault().get( TestSourceClass.class.getName())), EasyMock.eq(dst), (MimicMode) EasyMock.anyObject(), (MimicMethod[]) EasyMock.anyObject()); EasyMock.replay(mimicMock); mimicProcessor.applyTransformations(dst); EasyMock.verify(mimicMock); }
@Test public void testTransform_with_mimic_fields_only() throws Exception { addMimicAnnotation(dst, TestSourceClass.class.getName(), false, true, false, false); final MimicCreator mimicMock = EasyMock.createMock(MimicCreator.class); Guice.createInjector(new MimicCreatorTestModule(mimicMock)) .injectMembers(mimicProcessor); mimicMock.mimicFields( EasyMock.eq(ClassPool.getDefault().get( TestSourceClass.class.getName())), EasyMock.eq(dst)); EasyMock.replay(mimicMock); mimicProcessor.applyTransformations(dst); EasyMock.verify(mimicMock); }
@Test public void testTransform_with_mimic_interfaces_only() throws Exception { addMimicAnnotation(dst, TestSourceClass.class.getName(), true, false, false, false); final MimicCreator mimicMock = EasyMock.createMock(MimicCreator.class); Guice.createInjector(new MimicCreatorTestModule(mimicMock)) .injectMembers(mimicProcessor); mimicMock.mimicInterfaces( EasyMock.eq(ClassPool.getDefault().get( TestSourceClass.class.getName())), EasyMock.eq(dst)); EasyMock.replay(mimicMock); mimicProcessor.applyTransformations(dst); EasyMock.verify(mimicMock); }
@Test public void testTransform_with_mimic_methods_only() throws Exception { addMimicAnnotation(dst, TestSourceClass.class.getName(), false, false, false, true); final MimicCreator mimicMock = EasyMock.createMock(MimicCreator.class); Guice.createInjector(new MimicCreatorTestModule(mimicMock)) .injectMembers(mimicProcessor); mimicMock.mimicMethods( EasyMock.eq(ClassPool.getDefault().get( TestSourceClass.class.getName())), EasyMock.eq(dst), (MimicMode) EasyMock.anyObject(), (MimicMethod[]) EasyMock.anyObject()); EasyMock.replay(mimicMock); mimicProcessor.applyTransformations(dst); EasyMock.verify(mimicMock); }