Package net.jqwik.api.lifecycle
Interface LifecycleContext
-
- All Known Subinterfaces:
ContainerLifecycleContext
,PropertyLifecycleContext
,TryLifecycleContext
@API(status=EXPERIMENTAL, since="1.0") public interface LifecycleContext
Supertype of all lifecycle context interfaces.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends java.lang.annotation.Annotation>
java.util.Optional<T>findAnnotation(java.lang.Class<T> annotationClass)
Retrieve an annotation if present at the current test element.<T extends java.lang.annotation.Annotation>
java.util.List<T>findAnnotationsInContainer(java.lang.Class<T> annotationClass)
Retrieve an annotation if present in the current element's containers.java.lang.String
label()
The elements label under which it shows up in test reports and IDEs.<T> T
newInstance(java.lang.Class<T> clazz)
Create a new instance of aclazz
in the context of the property in which it is running.java.util.Optional<java.lang.Class<?>>
optionalContainerClass()
If the context refers to a class or a method the class or the method's class is returned, otherwiseOptional.empty()
java.util.Optional<java.lang.reflect.AnnotatedElement>
optionalElement()
If the context refers to a class or a method the class or method is returned, otherwiseOptional.empty()
Reporter
reporter()
Get hold of test reporter for publishing additional information on a test container or method.java.util.Optional<ResolveParameterHook.ParameterSupplier>
resolveParameter(java.lang.reflect.Executable executable, int index)
Resolve a parameter from a method in the context of the property in which it is running.
-
-
-
Method Detail
-
label
java.lang.String label()
The elements label under which it shows up in test reports and IDEs.- Returns:
- a String
-
optionalElement
@API(status=EXPERIMENTAL, since="1.2.5") java.util.Optional<java.lang.reflect.AnnotatedElement> optionalElement()
If the context refers to a class or a method the class or method is returned, otherwiseOptional.empty()
- Returns:
- an optional annotated element
-
optionalContainerClass
@API(status=EXPERIMENTAL, since="1.2.5") java.util.Optional<java.lang.Class<?>> optionalContainerClass()
If the context refers to a class or a method the class or the method's class is returned, otherwiseOptional.empty()
- Returns:
- an optional annotated element
-
reporter
@API(status=EXPERIMENTAL, since="1.2.3") Reporter reporter()
Get hold of test reporter for publishing additional information on a test container or method.- Returns:
- Current instance to test reporter
-
findAnnotation
@API(status=EXPERIMENTAL, since="1.2.4") <T extends java.lang.annotation.Annotation> java.util.Optional<T> findAnnotation(java.lang.Class<T> annotationClass)
Retrieve an annotation if present at the current test element.- Type Parameters:
T
- The annotation type- Parameters:
annotationClass
- The annotation type- Returns:
- instance of annotation type
-
findAnnotationsInContainer
@API(status=EXPERIMENTAL, since="1.2.4") <T extends java.lang.annotation.Annotation> java.util.List<T> findAnnotationsInContainer(java.lang.Class<T> annotationClass)
Retrieve an annotation if present in the current element's containers. Search up the container stack. Closest container annotations come first in list.- Type Parameters:
T
- The annotation type- Parameters:
annotationClass
- The annotation type- Returns:
- list of annotation objects
-
newInstance
@API(status=EXPERIMENTAL, since="1.2.4") <T> T newInstance(java.lang.Class<T> clazz)
Create a new instance of aclazz
in the context of the property in which it is running. Use this method for instance when trying to instantiate a class retrieved from an annotation's attribute.The behaviour of this method differs from
Class.newInstance()
if the class to instantiate is a non-static member of the container class or even a nested container class.- Type Parameters:
T
- The type to instantiate- Parameters:
clazz
- The class to instantiate- Returns:
- a freshly created instance of class
clazz
-
resolveParameter
@API(status=EXPERIMENTAL, since="1.2.5") java.util.Optional<ResolveParameterHook.ParameterSupplier> resolveParameter(java.lang.reflect.Executable executable, int index)
Resolve a parameter from a method in the context of the property in which it is running.- Parameters:
executable
- The executable of the test container the parameter of which should be resolvedindex
- The parameter's position in a method - starting with 0.- Returns:
- supplier instance
- Throws:
CannotResolveParameterException
- if parameter cannot be resolved
-
-