Class 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
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

        org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.concurrent.atomic.AtomicLong KEY_GENERATOR  
      private static org.junit.jupiter.api.extension.ExtensionContext.Namespace NAMESPACE  
      private static java.util.concurrent.locks.Lock SHARED_ANNOTATION_RESOLUTION_LOCK  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private <T> T checkType​(java.lang.Object resource, java.lang.Class<T> type)  
      private java.lang.String factoryKey​(Shared sharedAnnotation)  
      private java.util.concurrent.locks.ReentrantLock findLockForShared​(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.Method getMethod​(java.lang.Class<?> clazz, java.lang.String method, java.lang.Class<?>... parameterTypes)  
      private boolean hasAnnotation​(java.lang.reflect.Parameter parameter, Shared sharedAnnotation)  
      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)  
      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)  
      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)  
      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)  
      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)  
      <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)  
      <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)  
      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)  
      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)  
      private <T> T invokeWithLocks​(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, java.util.List<java.util.concurrent.locks.ReentrantLock> locks)  
      private java.lang.String keyOfFactoryKey​(Shared sharedAnnotation)  
      private Resource<?> newResource​(java.lang.Object newOrSharedAnnotation, ResourceFactory<?> resourceFactory)  
      private void putNewLockForShared​(Shared shared, org.junit.jupiter.api.extension.ExtensionContext.Store store)  
      private java.lang.Object resolveNew​(New newAnnotation, org.junit.jupiter.api.extension.ExtensionContext.Store store)  
      java.lang.Object resolveParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      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)  
      private java.lang.String resourceKey​(Shared sharedAnnotation)  
      private java.lang.String resourceLockKey​(Shared sharedAnnotation)  
      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)  
      private org.junit.jupiter.api.extension.ExtensionContext scopedContext​(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Shared.Scope scope)  
      private org.junit.jupiter.api.extension.ExtensionContext.Store scopedStore​(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Shared.Scope scope)  
      private java.lang.String sharedAnnotationKey​(Shared sharedAnnotation)  
      private java.util.List<java.util.concurrent.locks.ReentrantLock> sortedLocksForSharedResources​(java.util.Collection<Shared> sharedAnnotations, org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      boolean supportsParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      private java.lang.reflect.Method testFactoryMethod​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      private java.lang.String testMethodDescription​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      private void throwIfHasAnnotationWithSameNameButDifferentScope​(org.junit.jupiter.api.extension.ExtensionContext.Store rootStore, Shared sharedAnnotation)  
      private void throwIfHasAnnotationWithSameNameButDifferentType​(org.junit.jupiter.api.extension.ExtensionContext.Store scopedStore, Shared sharedAnnotation)  
      private void throwIfMultipleParametersHaveExactAnnotation​(java.lang.reflect.Parameter[] parameters, Shared sharedAnnotation)  
      private long uniqueKey()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

        interceptDynamicTest
    • 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
    • Constructor Detail

      • ResourceExtension

        ResourceExtension()
    • Method Detail

      • supportsParameter

        public boolean supportsParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext,
                                         org.junit.jupiter.api.extension.ExtensionContext extensionContext)
        Specified by:
        supportsParameter in interface org.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:
        resolveParameter in interface org.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:
        interceptTestMethod in interface org.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:
        interceptTestFactoryMethod in interface org.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:
        interceptDynamicTest in interface org.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:
        interceptTestTemplateMethod in interface org.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:
        interceptTestClassConstructor in interface org.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:
        interceptBeforeAllMethod in interface org.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:
        interceptAfterAllMethod in interface org.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:
        interceptBeforeEachMethod in interface org.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:
        interceptAfterEachMethod in interface org.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