MdsWeavingHook implements WeavingHook { @Override public void weave(WovenClass wovenClass) { String className = wovenClass.getClassName(); if (className.startsWith("org.slf4j")) { return; } LOGGER.trace("Weaving called for: {}", className); ClassData enhancedClassData = MotechClassPool.getEnhancedClassData(className); if (enhancedClassData == null) { LOGGER.trace("The class doesn't have enhanced metadata: {}", className); } else { LOGGER.info("Weaving {}", className); addCommonImports(wovenClass); addDynamicImports(wovenClass); wovenClass.setBytes(enhancedClassData.getBytecode()); } }  @Override void weave(WovenClass wovenClass); static final String[] STANDARD_DYNAMIC_IMPORTS; }
@Test public void shouldWeaveClassesForDdeAndAddImports() { MotechClassPool.registerEnhancedClassData(new ClassData(TEST_CLASS, "testClassContent".getBytes())); List<String> dynamicImports = new ArrayList<>(asList("one.two.three")); when(wovenClass.getClassName()).thenReturn(TEST_CLASS); when(wovenClass.getDynamicImports()).thenReturn(dynamicImports); mdsWeavingHook.weave(wovenClass); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(wovenClass).setBytes(captor.capture()); assertArrayEquals("testClassContent".getBytes(), captor.getValue()); assertThat(dynamicImports, hasItem("one.two.three")); for (String sdi : MdsWeavingHook.STANDARD_DYNAMIC_IMPORTS) { assertThat(dynamicImports, hasItem(sdi)); } }