Class TestClassMaker
java.lang.Object
io.quarkus.gizmo2.testing.TestClassMaker
A utility for testing generated classes which may be used in a unit test.
The functions of this class are not thread-safe and are not usable for concurrency testing.
By default, defined classes have assertions enabled.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the class loader associated with this instance.<T> Tconstructor(Class<?> clazz, Class<T> proxyType) Look up a constructor on a class defined to this test class maker.<T> Tconstructor(Class<?> clazz, MethodType methodType, Class<T> proxyType) Look up a constructor on a class defined to this test class maker.<T> Tconstructor(ClassDesc classDesc, Class<T> proxyType) Look up a constructor on a class defined to this test class maker.<T> Tconstructor(ClassDesc classDesc, MethodType methodType, Class<T> proxyType) Look up a constructor on a class defined to this test class maker.<T> Tconstructor(String className, Class<T> proxyType) Look up a constructor on a class defined to this test class maker.<T> Tconstructor(String className, MethodType methodType, Class<T> proxyType) Look up a constructor on a class defined to this test class maker.static TestClassMakercreate()Construct a new instance.static TestClassMakerConstruct a new instance.gizmo()Returns the configured Gizmo instance (notnull).voidinitializeClass(Class<?> clazz) Initialize a class defined by this test class maker.Class<?> Load a class from this loader with the given descriptor.<T> Class<? extends T> Load a class from this loader with the given descriptor.Class<?> Load a class from this loader with the given name.<T> Class<? extends T> Load a class from this loader with the given name.<T> TnewInstance(Class<T> clazz) Construct a new instance using a no-argument constructor on the class.<T> TnewInstance(ClassDesc classDesc, Class<T> expectedType) Construct a new instance using a no-argument constructor on the class.<T> TnewInstance(String className, Class<T> expectedType) Construct a new instance using a no-argument constructor on the class.<T> TRead the bytes of a class and apply a transformation to them.<T> TRead the bytes of a class and apply a transformation to them.voidregisterResource(String path, byte[] data) Register a new resource with this loader.voidregisterResource(String path, String data) Register a new resource with this loader.voidregisterResource(String path, List<String> lines) Register a new resource with this loader.<T> TstaticMethod(Class<?> clazz, String methodName, Class<T> proxyType) Look up a static method on a class defined to this test class maker.<T> TstaticMethod(Class<?> clazz, String methodName, MethodType methodType, Class<T> proxyType) Look up a static method on a class defined to this test class maker.<T> TstaticMethod(ClassDesc classDesc, String methodName, Class<T> proxyType) Look up a static method on a class defined to this test class maker.<T> TstaticMethod(ClassDesc classDesc, String methodName, MethodType methodType, Class<T> proxyType) Look up a static method on a class defined to this test class maker.<T> TstaticMethod(String className, String methodName, Class<T> proxyType) Look up a static method on a class defined to this test class maker.<T> TstaticMethod(String className, String methodName, MethodType methodType, Class<T> proxyType) Look up a static method on a class defined to this test class maker.<T> TvirtualMethod(Class<?> clazz, String methodName, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.<T> TvirtualMethod(Class<?> clazz, String methodName, MethodType methodType, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.<T> TvirtualMethod(ClassDesc classDesc, String methodName, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.<T> TvirtualMethod(ClassDesc classDesc, String methodName, MethodType methodType, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.<T> TvirtualMethod(String className, String methodName, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.<T> TvirtualMethod(String className, String methodName, MethodType methodType, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.
-
Method Details
-
create
Construct a new instance. The givengizmois used, except for its class output configuration which is ignored.- Parameters:
gizmo- the configured ase Gizmo instance to use (must not benull)- Returns:
- a new test class maker instance (not
null)
-
create
Construct a new instance.- Returns:
- a new test class maker instance (not
null)
-
gizmo
Returns the configured Gizmo instance (notnull). The given instance can be used to create new classes and interfaces.- Returns:
- the configured Gizmo instance (not
null)
-
classLoader
Returns the class loader associated with this instance. All test classes are defined to this loader.- Returns:
- the class loader associated with this instance
-
registerResource
Register a new resource with this loader. The lines of text are encoded using theUTF-8character encoding. Each given line of text is terminated with a newline character (NLaka0x0D (12)).- Parameters:
path- the resource path (must not benull)lines- the lines of text for the resource (must not benull)
-
registerResource
-
registerResource
Register a new resource with this loader.- Parameters:
path- the resource path (must not benull)data- the binary data of the resource (must not benull)
-
loadClass
Load a class from this loader with the given name.- Parameters:
className- the name of the class to load (must not benull)- Returns:
- the loaded class (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader
-
loadClass
Load a class from this loader with the given descriptor.- Parameters:
classDesc- the descriptor of the class to load (must not benull)- Returns:
- the loaded class (not
null) - Throws:
NoSuchElementException- if there is no class with that descriptor defined to this class loader
-
loadClass
Load a class from this loader with the given name.- Parameters:
className- the name of the class to load (must not benull)expectedSupertype- the expected supertype of the class (must not benull)- Returns:
- the loaded class (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loaderClassCastException- if the loaded class is not of the given type
-
loadClass
Load a class from this loader with the given descriptor.- Parameters:
classDesc- the descriptor of the class to load (must not benull)expectedSupertype- the expected supertype of the class (must not benull)- Returns:
- the loaded class (not
null) - Throws:
NoSuchElementException- if there is no class with that descriptor defined to this class loaderClassCastException- if the loaded class is not of the given type
-
readClass
Read the bytes of a class and apply a transformation to them.- Type Parameters:
T- the result type- Parameters:
className- the name of the class to read (must not benull)func- the function to apply (must not benull)- Returns:
- the interpreted class
- Throws:
NoSuchElementException- if there is no class with that name defined to this class loader
-
readClass
Read the bytes of a class and apply a transformation to them.- Type Parameters:
T- the result type- Parameters:
classDesc- the descriptor of the class to read (must not benull)func- the function to apply (must not benull)- Returns:
- the interpreted class
- Throws:
NoSuchElementException- if there is no class with that descriptor defined to this class loader
-
initializeClass
Initialize a class defined by this test class maker.- Parameters:
clazz- the class to initialize (must not benull)- Throws:
IllegalArgumentException- if this test class maker does not own the given class
-
staticMethod
Look up a static method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
className- the owner class binary name (must not benull)methodName- the method name (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
staticMethod
public <T> T staticMethod(String className, String methodName, MethodType methodType, Class<T> proxyType) Look up a static method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
className- the owner class binary name (must not benull)methodName- the method name (must not benull)methodType- the type of the static class (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
staticMethod
Look up a static method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
classDesc- the owner class descriptor (must not benull)methodName- the method name (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
staticMethod
public <T> T staticMethod(ClassDesc classDesc, String methodName, MethodType methodType, Class<T> proxyType) Look up a static method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
classDesc- the owner class descriptor (must not benull)methodName- the method name (must not benull)methodType- the type of the static class (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
staticMethod
Look up a static method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
clazz- the owner class (must not benull)methodName- the method name (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
staticMethod
public <T> T staticMethod(Class<?> clazz, String methodName, MethodType methodType, Class<T> proxyType) Look up a static method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
clazz- the owner class (must not benull)methodName- the method name (must not benull)methodType- the type of the static method (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
virtualMethod
Look up a virtual method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
className- the owner class binary name (must not benull)methodName- the method name (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
virtualMethod
public <T> T virtualMethod(String className, String methodName, MethodType methodType, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
className- the owner class binary name (must not benull)methodName- the method name (must not benull)methodType- the type of the static method (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
virtualMethod
Look up a virtual method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
classDesc- the owner class descriptor (must not benull)methodName- the method name (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
virtualMethod
public <T> T virtualMethod(ClassDesc classDesc, String methodName, MethodType methodType, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
classDesc- the owner class descriptor (must not benull)methodName- the method name (must not benull)methodType- the type of the virtual method (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
virtualMethod
Look up a virtual method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
clazz- the owner class (must not benull)methodName- the method name (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
virtualMethod
public <T> T virtualMethod(Class<?> clazz, String methodName, MethodType methodType, Class<T> proxyType) Look up a virtual method on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
clazz- the owner class (must not benull)methodName- the method name (must not benull)methodType- the type of the virtual method (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target method (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no method which matches the expected name and type
-
constructor
Look up a constructor on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
className- the owner class binary name (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target constructor (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no constructor which matches the expected type
-
constructor
Look up a constructor on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
className- the owner class binary name (must not benull)methodType- the type of the constructor (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target constructor (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no constructor which matches the expected type
-
constructor
Look up a constructor on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
classDesc- the owner class descriptor (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target constructor (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no constructor which matches the expected type
-
constructor
Look up a constructor on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
classDesc- the owner class descriptor (must not benull)methodType- the type of the constructor (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target constructor (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no constructor which matches the expected type
-
constructor
Look up a constructor on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
clazz- the owner class (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target constructor (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no constructor which matches the expected type
-
constructor
Look up a constructor on a class defined to this test class maker.- Type Parameters:
T- the type of the proxy interface- Parameters:
clazz- the owner class (must not benull)methodType- the type of the constructor (must not benull)proxyType- theClassof the proxy interface (must not benull)- Returns:
- the proxy instance which invokes the target constructor (not
null) - Throws:
NoSuchElementException- if there is no class with that name defined to this class loader, or if there is no constructor which matches the expected type
-
newInstance
Construct a new instance using a no-argument constructor on the class.- Type Parameters:
T- the expected type- Parameters:
className- the owner class binary name (must not benull)expectedType- the expected type of the instance (must not benull)- Returns:
- the new instance, cast to the given expected type
-
newInstance
Construct a new instance using a no-argument constructor on the class.- Type Parameters:
T- the expected type- Parameters:
classDesc- the owner class descriptor (must not benull)expectedType- the expected type of the instance (must not benull)- Returns:
- the new instance, cast to the given expected type
-
newInstance
Construct a new instance using a no-argument constructor on the class.- Type Parameters:
T- the expected type- Parameters:
clazz- the owner class (must not benull)- Returns:
- the new instance
-