Package de.xima.fc.testhelper
Class FilteredClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- de.xima.fc.testhelper.FilteredClassLoader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class FilteredClassLoader extends URLClassLoader
Similar toorg.springframework.boot.test.context.FilteredClassLoader
, but ensures thatgetResources(String)
does not return excluded resources.
-
-
Constructor Summary
Constructors Constructor Description FilteredClassLoader(Class<?>... hiddenClasses)
Create aFilteredClassLoader
that hides the given classes.FilteredClassLoader(String... hiddenPackages)
Create aFilteredClassLoader
that hides classes from the given packages.FilteredClassLoader(Predicate<String>... filters)
Create aFilteredClassLoader
that filters based on the given predicate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description URL
getResource(String name)
InputStream
getResourceAsStream(String name)
Enumeration<URL>
getResources(String name)
protected Class<?>
loadClass(String name, boolean resolve)
-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
-
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
FilteredClassLoader
public FilteredClassLoader(Class<?>... hiddenClasses)
Create aFilteredClassLoader
that hides the given classes.- Parameters:
hiddenClasses
- the classes to hide
-
FilteredClassLoader
@SafeVarargs public FilteredClassLoader(Predicate<String>... filters)
Create aFilteredClassLoader
that filters based on the given predicate.- Parameters:
filters
- a set of filters to determine when a class name or resource should be hidden. Aresult
oftrue
indicates a filtered class or resource. The input of the predicate can either be the binary name of a class or a resource name.
-
FilteredClassLoader
public FilteredClassLoader(String... hiddenPackages)
Create aFilteredClassLoader
that hides classes from the given packages.- Parameters:
hiddenPackages
- the packages to hide
-
-
Method Detail
-
getResource
public URL getResource(String name)
- Overrides:
getResource
in classClassLoader
-
getResourceAsStream
public InputStream getResourceAsStream(String name)
- Overrides:
getResourceAsStream
in classURLClassLoader
-
getResources
public Enumeration<URL> getResources(String name) throws IOException
- Overrides:
getResources
in classClassLoader
- Throws:
IOException
-
loadClass
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
-