- java.lang.Object
-
- org.junitpioneer.jupiter.resource.ResourceExtension
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.InvocationInterceptor,org.junit.jupiter.api.extension.ParameterResolver
class ResourceExtension extends java.lang.Object implements org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.InvocationInterceptor
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.concurrent.atomic.AtomicLongKEY_GENERATORprivate static org.junit.jupiter.api.extension.ExtensionContext.NamespaceNAMESPACEprivate static java.util.concurrent.locks.LockSHARED_ANNOTATION_RESOLUTION_LOCK
-
Constructor Summary
Constructors Constructor Description ResourceExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private <T> TcheckType(java.lang.Object resource, java.lang.Class<T> type)private java.lang.StringfactoryKey(Shared sharedAnnotation)private java.util.concurrent.locks.ReentrantLockfindLockForShared(Shared shared, org.junit.jupiter.api.extension.ExtensionContext.Store store)private java.util.List<Shared>findShared(java.lang.reflect.Executable executable)private java.lang.reflect.MethodgetMethod(java.lang.Class<?> clazz, java.lang.String method, java.lang.Class<?>... parameterTypes)private booleanhasAnnotation(java.lang.reflect.Parameter parameter, Shared sharedAnnotation)voidinterceptAfterAllMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)voidinterceptAfterEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)voidinterceptBeforeAllMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)voidinterceptBeforeEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)voidinterceptDynamicTest(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.DynamicTestInvocationContext invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)<T> TinterceptTestClassConstructor(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Constructor<T>> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)<T> TinterceptTestFactoryMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)voidinterceptTestMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)voidinterceptTestTemplateMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)private <T> TinvokeWithLocks(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, java.util.List<java.util.concurrent.locks.ReentrantLock> locks)private java.lang.StringkeyOfFactoryKey(Shared sharedAnnotation)private Resource<?>newResource(java.lang.Object newOrSharedAnnotation, ResourceFactory<?> resourceFactory)private voidputNewLockForShared(Shared shared, org.junit.jupiter.api.extension.ExtensionContext.Store store)private java.lang.ObjectresolveNew(New newAnnotation, org.junit.jupiter.api.extension.ExtensionContext.Store store)java.lang.ObjectresolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)private java.lang.ObjectresolveShared(Shared sharedAnnotation, java.lang.reflect.Parameter[] parameters, org.junit.jupiter.api.extension.ExtensionContext.Store scopedStore, org.junit.jupiter.api.extension.ExtensionContext.Store rootStore)private java.lang.StringresourceKey(Shared sharedAnnotation)private java.lang.StringresourceLockKey(Shared sharedAnnotation)private <T> TrunSequentially(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, java.lang.reflect.Executable executable, org.junit.jupiter.api.extension.ExtensionContext extensionContext)private org.junit.jupiter.api.extension.ExtensionContextscopedContext(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Shared.Scope scope)private org.junit.jupiter.api.extension.ExtensionContext.StorescopedStore(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Shared.Scope scope)private java.lang.StringsharedAnnotationKey(Shared sharedAnnotation)private java.util.List<java.util.concurrent.locks.ReentrantLock>sortedLocksForSharedResources(java.util.Collection<Shared> sharedAnnotations, org.junit.jupiter.api.extension.ExtensionContext extensionContext)booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)private java.lang.reflect.MethodtestFactoryMethod(org.junit.jupiter.api.extension.ExtensionContext extensionContext)private java.lang.StringtestMethodDescription(org.junit.jupiter.api.extension.ExtensionContext extensionContext)private voidthrowIfHasAnnotationWithSameNameButDifferentScope(org.junit.jupiter.api.extension.ExtensionContext.Store rootStore, Shared sharedAnnotation)private voidthrowIfHasAnnotationWithSameNameButDifferentType(org.junit.jupiter.api.extension.ExtensionContext.Store scopedStore, Shared sharedAnnotation)private voidthrowIfMultipleParametersHaveExactAnnotation(java.lang.reflect.Parameter[] parameters, Shared sharedAnnotation)private longuniqueKey()
-
-
-
Field Detail
-
NAMESPACE
private static final org.junit.jupiter.api.extension.ExtensionContext.Namespace NAMESPACE
-
SHARED_ANNOTATION_RESOLUTION_LOCK
private static final java.util.concurrent.locks.Lock SHARED_ANNOTATION_RESOLUTION_LOCK
-
KEY_GENERATOR
private static final java.util.concurrent.atomic.AtomicLong KEY_GENERATOR
-
-
Method Detail
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)- Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
resolveParameter
public java.lang.Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException- Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
checkType
private <T> T checkType(java.lang.Object resource, java.lang.Class<T> type)
-
resolveNew
private java.lang.Object resolveNew(New newAnnotation, org.junit.jupiter.api.extension.ExtensionContext.Store store)
-
resolveShared
private java.lang.Object resolveShared(Shared sharedAnnotation, java.lang.reflect.Parameter[] parameters, org.junit.jupiter.api.extension.ExtensionContext.Store scopedStore, org.junit.jupiter.api.extension.ExtensionContext.Store rootStore)
-
newResource
private Resource<?> newResource(java.lang.Object newOrSharedAnnotation, ResourceFactory<?> resourceFactory)
-
throwIfHasAnnotationWithSameNameButDifferentType
private void throwIfHasAnnotationWithSameNameButDifferentType(org.junit.jupiter.api.extension.ExtensionContext.Store scopedStore, Shared sharedAnnotation)
-
throwIfHasAnnotationWithSameNameButDifferentScope
private void throwIfHasAnnotationWithSameNameButDifferentScope(org.junit.jupiter.api.extension.ExtensionContext.Store rootStore, Shared sharedAnnotation)
-
throwIfMultipleParametersHaveExactAnnotation
private void throwIfMultipleParametersHaveExactAnnotation(java.lang.reflect.Parameter[] parameters, Shared sharedAnnotation)
-
hasAnnotation
private boolean hasAnnotation(java.lang.reflect.Parameter parameter, Shared sharedAnnotation)
-
uniqueKey
private long uniqueKey()
-
factoryKey
private java.lang.String factoryKey(Shared sharedAnnotation)
-
resourceKey
private java.lang.String resourceKey(Shared sharedAnnotation)
-
resourceLockKey
private java.lang.String resourceLockKey(Shared sharedAnnotation)
-
keyOfFactoryKey
private java.lang.String keyOfFactoryKey(Shared sharedAnnotation)
-
sharedAnnotationKey
private java.lang.String sharedAnnotationKey(Shared sharedAnnotation)
-
testMethodDescription
private java.lang.String testMethodDescription(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
getMethod
private java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String method, java.lang.Class<?>... parameterTypes)
-
interceptTestMethod
public void interceptTestMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptTestMethodin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
interceptTestFactoryMethod
public <T> T interceptTestFactoryMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptTestFactoryMethodin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
interceptDynamicTest
public void interceptDynamicTest(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.DynamicTestInvocationContext invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptDynamicTestin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
interceptTestTemplateMethod
public void interceptTestTemplateMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptTestTemplateMethodin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
interceptTestClassConstructor
public <T> T interceptTestClassConstructor(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Constructor<T>> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptTestClassConstructorin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
interceptBeforeAllMethod
public void interceptBeforeAllMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptBeforeAllMethodin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
interceptAfterAllMethod
public void interceptAfterAllMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptAfterAllMethodin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
interceptBeforeEachMethod
public void interceptBeforeEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptBeforeEachMethodin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
interceptAfterEachMethod
public void interceptAfterEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Specified by:
interceptAfterEachMethodin interfaceorg.junit.jupiter.api.extension.InvocationInterceptor- Throws:
java.lang.Throwable
-
runSequentially
private <T> T runSequentially(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, java.lang.reflect.Executable executable, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Throwable- Throws:
java.lang.Throwable
-
sortedLocksForSharedResources
private java.util.List<java.util.concurrent.locks.ReentrantLock> sortedLocksForSharedResources(java.util.Collection<Shared> sharedAnnotations, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
testFactoryMethod
private java.lang.reflect.Method testFactoryMethod(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
scopedStore
private org.junit.jupiter.api.extension.ExtensionContext.Store scopedStore(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Shared.Scope scope)
-
scopedContext
private org.junit.jupiter.api.extension.ExtensionContext scopedContext(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Shared.Scope scope)
-
findShared
private java.util.List<Shared> findShared(java.lang.reflect.Executable executable)
-
putNewLockForShared
private void putNewLockForShared(Shared shared, org.junit.jupiter.api.extension.ExtensionContext.Store store)
-
findLockForShared
private java.util.concurrent.locks.ReentrantLock findLockForShared(Shared shared, org.junit.jupiter.api.extension.ExtensionContext.Store store)
-
invokeWithLocks
private <T> T invokeWithLocks(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, java.util.List<java.util.concurrent.locks.ReentrantLock> locks) throws java.lang.Throwable- Throws:
java.lang.Throwable
-
-