CoverageTransformer implements ClassFileTransformer { @Override public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined, final ProtectionDomain protectionDomain, final byte[] classfileBuffer) throws IllegalClassFormatException { final boolean include = shouldInclude(className); if (include) { try { return transformBytes(loader, className, classfileBuffer); } catch (final RuntimeException t) { System.err.println("RuntimeException while transforming " + className); throw t; } } else { return null; } } CoverageTransformer(final Predicate<String> filter); @Override byte[] transform(final ClassLoader loader, final String className,
      final Class<?> classBeingRedefined,
      final ProtectionDomain protectionDomain, final byte[] classfileBuffer);  }
@Test public void shouldNotTransformClassesNotMatchingPredicate() throws IllegalClassFormatException { final CoverageTransformer testee = new CoverageTransformer(s -> false); assertNull(testee.transform(null, "anything", null, null, null)); }
@Test public void shouldTransformClasseMatchingPredicate() throws IllegalClassFormatException { final CoverageTransformer testee = new CoverageTransformer(s -> true); final byte[] bs = this.bytes.getBytes(String.class.getName()).get(); assertFalse(Arrays.equals(bs, testee.transform(null, "anything", null, null, bs))); }