MimicProcessor extends ClassTransformer { @Override protected boolean shouldTransform(CtClass candidateClass) throws Exception { if (candidateClass.getDeclaringClass() != null && (candidateClass.getModifiers() & Modifier.STATIC) == 0) { return false; } return candidateClass.hasAnnotation(Mimic.class); } MimicProcessor();   }
@Test public void testShouldTransform_does_filter_correctly_a_mimic_annotation() throws Exception { addMimicAnnotation(dst, src.getName(), true, true, true, true); boolean filter = mimicProcessor.shouldTransform(dst); assertTrue(filter); }
@Test public void testShouldTransform_does_filter_correctly_a_class_with_no_mimic_annotation() throws Exception { boolean filter = mimicProcessor.shouldTransform(dst); assertFalse(filter); }
@Test public void testShouldTransform_does_filter_correctly_a_non_static_inner_class() throws Exception { dst = new CtClass("Dst" + TestCounter.testCounter) { @Override public CtClass[] getDeclaredClasses() throws NotFoundException { CtClass inner = new CtClass("Inner" + TestCounter.testCounter) { @Override public CtClass getDeclaringClass() throws NotFoundException { return dst; } @Override public int getModifiers() { return Modifier.PUBLIC; } }; return new CtClass[] {inner}; } }; boolean filter = mimicProcessor.shouldTransform(dst.getDeclaredClasses()[0]); assertFalse(filter); }