RootTransformer { public byte[] transformType(CtClass affectedClass) throws Exception { if (affectedClass.isInterface()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("transformation aborted, as class is an interface"); } return null; } if (!affectedClass.hasAnnotation(Transformed.class)) { transformClass(affectedClass); } if (xmlConfiguration.getGlobalConfiguration().writeTransformedClasses()) { affectedClass.writeFile(xmlConfiguration.getGlobalConfiguration().writeTransformedClassesDirectory()); } return affectedClass.toBytecode(); } private  RootTransformer(); void init(); byte[] transformType(CtClass affectedClass); void updateClassPath(ClassLoader loader, byte[] classfileBuffer, String className); XmlConfigurationManager getXmlConfiguration(); static final RootTransformer INSTANCE; }
@Test public void testTransformClassInterface() throws Exception { assertNull(transformer.transformType(pool.get(EmptyInterface.class.getName()))); }
@SuppressWarnings("unchecked") @Test public void testTransformClassTargetClass() throws Exception { assertNotNull(transformer.transformType(pool.get(TargetClass.class.getName()))); assertEquals(targetClass, ContractRegistry.INSTANCE.getContractInfo(contractClass).getTargetClass()); assertEquals(contractClass, ContractRegistry.INSTANCE.getContractInfo(contractClass).getContractClass()); verify(targetClassTransformer).transform(any(ListOrderedSet.class), argThat(new ArgumentMatcher<ListOrderedSet<ContractInfo>>() { @Override public boolean matches(Object argument) { ListOrderedSet<ContractInfo> contractInfos = (ListOrderedSet<ContractInfo>) argument; return contractInfos != null && contractInfos.size() == 1 && contractInfos.iterator().next().getTargetClass().equals(targetClass) && contractInfos.iterator().next().getContractClass().equals(contractClass); } }), eq(targetClass)); }
@Test public void testTransformClassContractClass() throws Exception { ContractRegistry.INSTANCE.registerContract(targetClass, contractClass); assertNotNull(transformer.transformType(pool.get(ContractClass.class.getName()))); verify(contractClassTransformer).transform(argThat(new ArgumentMatcher<ContractInfo>() { @Override public boolean matches(Object argument) { ContractInfo contractInfo = (ContractInfo) argument; return contractInfo != null && contractInfo.getTargetClass().equals(targetClass) && contractInfo.getContractClass().equals(contractClass); } }), eq(contractClass)); }
@Test public void testTransformClassUninvolvedClass() throws Exception { assertNotNull(transformer.transformType(pool.get(UninvolvedClass.class.getName()))); }