MimicCreator { public void mimicFields(CtClass src, CtClass dst) throws MimicException, CannotCompileException { for (CtField field : src.getDeclaredFields()) { if (hasField(dst, field)) { throw new MimicException(String.format("Class %s already has a field named %s %n", dst.getName(), field.getName())); } dst.addField(new CtField(field, dst)); } } MimicCreator();  MimicCreator(String key); boolean hasField(CtClass clazz, CtField field); boolean hasInterface(CtClass dst, CtClass interfazz); void mimicClass(CtClass src, CtClass dst, MimicMode defaultMimicMode, MimicMethod[] mimicMethods); void mimicConstructors(CtClass src, CtClass dst); void mimicFields(CtClass src, CtClass dst); void mimicInterfaces(CtClass src, CtClass dst); void mimicMethods(CtClass src, CtClass dst, MimicMode defaultMimicMode, MimicMethod[] mimicMethods);  }
@Test public void testMimicFields() throws Exception { src.addField(new CtField(CtClass.intType, "foo", src)); mimicCreator.mimicFields(src, dst); Class<?> dstClass = dst.toClass(); assertHasFooField(dst); assertHasFooField(dstClass.newInstance(), 0); }
@Test(expected = MimicException.class) public void testMimicFields_with_same_field() throws Exception { src.addField(new CtField(CtClass.intType, "foo", src)); dst.addField(new CtField(CtClass.booleanType, "foo", dst)); mimicCreator.mimicFields(src, dst); }