Skip to content

Commit

Permalink
Support TestNG with @CompileWithTargetClassAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jul 31, 2022
1 parent e4395f2 commit 9dd7f54
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Set;

/**
* {@link ClassLoader} implementation to support
* {@link CompileWithTargetClassAccess @CompileWithTargetClassAccess}.
*
* @author Phillip Webb
* @author Sam Brannen
* @since 6.0
*/
final class CompileWithTargetClassAccessClassLoader extends ClassLoader {

private static final Set<String> passthroughPackages =
Set.of("org.junit", "org.testng", "org.hamcrest");

private final ClassLoader testClassLoader;


Expand All @@ -41,7 +46,7 @@ public CompileWithTargetClassAccessClassLoader(ClassLoader testClassLoader) {

@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if (name.startsWith("org.junit") || name.startsWith("org.hamcrest")) {
if (passthroughPackages.stream().anyMatch(pkg -> name.startsWith(pkg))) {
return Class.forName(name, false, this.testClassLoader);
}
return super.loadClass(name);
Expand Down

0 comments on commit 9dd7f54

Please sign in to comment.