org.junit.jupiter.api.extension.ExtensionContext.Namespace Java Examples
The following examples show how to use
org.junit.jupiter.api.extension.ExtensionContext.Namespace.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractUseDataProviderArgumentProviderTest.java From junit-dataprovider with Apache License 2.0 | 6 votes |
@Test void testInvokeDataProviderMethodToRetrieveDataShouldThrowParameterResolutionExceptionIfDataProviderInvocationThrows() throws Exception { // Given: Method dataProviderMethod = this.getClass().getDeclaredMethod( "testInvokeDataProviderMethodToRetrieveDataShouldThrowParameterResolutionExceptionIfDataProviderInvocationThrows"); when(extensionContext.getRoot()).thenReturn(extensionContext); when(extensionContext.getStore(any(Namespace.class))).thenReturn(store); // When: Exception result = assertThrows(ParameterResolutionException.class, () -> underTest.invokeDataProviderMethodToRetrieveData(dataProviderMethod, true, extensionContext)); // Then: assertThat(result).hasMessageMatching("Exception while invoking dataprovider method '.*': .*"); }
Example #2
Source File: MockitoExtension.java From hypergraphql with Apache License 2.0 | 5 votes |
private Object getMock(Parameter parameter, ExtensionContext extensionContext) { Class<?> mockType = parameter.getType(); Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType)); String mockName = getMockName(parameter); if (mockName != null) { return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)); } else { return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); } }
Example #3
Source File: InjectorUtils.java From bobcat with Apache License 2.0 | 5 votes |
/** * Retrieves injector from the context store using Namespace. If it is not present it searches in * parent context until it is found or there is end of hierarchy. * * @param context - extension context from junit5 extensions * @param namespace - Namespace for current test invocation * @return Injector or null if no injector is found */ public static Injector retrieveInjectorFromStore(ExtensionContext context, Namespace namespace) { AnnotatedElement element = context.getElement() .orElseThrow(() -> new NoSuchElementException("No element present")); return context.getStore(namespace).getOrComputeIfAbsent(element, absent -> retrieveInjectorFromStore( context.getParent().orElseThrow(() -> new NoSuchElementException("No injector found")), namespace), Injector.class); }
Example #4
Source File: DBUnitExtension.java From database-rider with Apache License 2.0 | 5 votes |
private static Optional<io.micronaut.context.ApplicationContext> getMicronautApplicationContext(ExtensionContext extensionContext) { Store micronautStore = extensionContext.getRoot().getStore(Namespace.create(MicronautJunit5Extension.class)); if (micronautStore != null) { try { io.micronaut.context.ApplicationContext appContext = (io.micronaut.context.ApplicationContext) micronautStore.get(io.micronaut.context.ApplicationContext.class); if (appContext != null) { return Optional.of(appContext); } } catch (ClassCastException ex) { } } return Optional.empty(); }
Example #5
Source File: DBUnitExtension.java From database-rider with Apache License 2.0 | 5 votes |
private boolean isSpringTestContextEnabled(ExtensionContext extensionContext) { if (!extensionContext.getTestClass().isPresent()) { return false; } Store springStore = extensionContext.getRoot().getStore(Namespace.create(SpringExtension.class)); return springStore != null && springStore.get(extensionContext.getTestClass().get()) != null; }
Example #6
Source File: DBUnitExtension.java From database-rider with Apache License 2.0 | 5 votes |
private boolean isSpringExtensionEnabled(ExtensionContext extensionContext) { try { return isOnClasspath("org.springframework.test.context.junit.jupiter.SpringExtension") && extensionContext.getRoot().getStore(Namespace.create(SpringExtension.class)) != null; } catch (Exception e) { return false; } }
Example #7
Source File: MockitoExtension.java From hypergraphql with Apache License 2.0 | 5 votes |
private Object getMock(Parameter parameter, ExtensionContext extensionContext) { Class<?> mockType = parameter.getType(); Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType)); String mockName = getMockName(parameter); if (mockName != null) { return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)); } else { return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); } }
Example #8
Source File: MockitoExtension.java From Mastering-Software-Testing-with-JUnit-5 with MIT License | 5 votes |
private Object getMock(Parameter parameter, ExtensionContext extensionContext) { Class<?> mockType = parameter.getType(); Store mocks = extensionContext .getStore(Namespace.create(MockitoExtension.class, mockType)); String mockName = getMockName(parameter); if (mockName != null) { return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)); } else { return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); } }
Example #9
Source File: MockitoExtension.java From Mastering-Software-Testing-with-JUnit-5 with MIT License | 5 votes |
private Object getMock(Parameter parameter, ExtensionContext extensionContext) { Class<?> mockType = parameter.getType(); Store mocks = extensionContext .getStore(Namespace.create(MockitoExtension.class, mockType)); String mockName = getMockName(parameter); if (mockName != null) { return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)); } else { return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); } }
Example #10
Source File: MockitoExtension.java From intellij-spring-assistant with MIT License | 5 votes |
private Object getMock(Parameter parameter, ExtensionContext extensionContext) { Class<?> mockType = parameter.getType(); Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType)); String mockName = getMockName(parameter); if (mockName != null) { return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)); } else { return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); } }
Example #11
Source File: TimingExtension.java From Mastering-Software-Testing-with-JUnit-5 with MIT License | 4 votes |
private Store getStore(ExtensionContext context) { return context.getStore(Namespace.create(getClass(), context)); }
Example #12
Source File: VertxExtension.java From vertx-junit5 with Apache License 2.0 | 4 votes |
private Store store(ExtensionContext extensionContext) { return extensionContext.getStore(Namespace.GLOBAL); }
Example #13
Source File: SkipOnFailuresInEnclosingClassExtension.java From junit5-demo with Apache License 2.0 | 4 votes |
private Store getStore(ExtensionContext context) { return context.getRoot().getStore(Namespace.create(getClass())); }
Example #14
Source File: CaptureSystemOutputExtension.java From junit5-demo with Apache License 2.0 | 4 votes |
private Store getStore(ExtensionContext context) { return context.getStore(Namespace.create(getClass(), context.getRequiredTestMethod())); }
Example #15
Source File: TimingExtension.java From junit5-demo with Apache License 2.0 | 4 votes |
private Store getStore(ExtensionContext context) { return context.getStore(Namespace.create(context.getRequiredTestMethod())); }
Example #16
Source File: TempDirectoryExtension.java From pdfcompare with Apache License 2.0 | 4 votes |
private Namespace localNamespace(ExtensionContext context) { return Namespace.create(TempDirectoryExtension.class, context); }
Example #17
Source File: TimingExtension.java From mastering-junit5 with Apache License 2.0 | 4 votes |
private Store getStore(ExtensionContext context) { return context.getStore(Namespace.create(getClass(), context)); }
Example #18
Source File: RestoreSystemPropertiesExtension.java From liquibase-percona with Apache License 2.0 | 4 votes |
private Store getStore(ExtensionContext context) { Namespace namespace = Namespace.create(getClass(), context.getRequiredTestMethod()); return context.getStore(namespace); }
Example #19
Source File: ExtensionContextParamResolver.java From GitToolBox with Apache License 2.0 | 4 votes |
public ExtensionContextParamResolver(Namespace namespace) { this(namespace, new EmptyResolver()); }
Example #20
Source File: ExtensionContextParamResolver.java From GitToolBox with Apache License 2.0 | 4 votes |
private ExtensionContextParamResolver(Namespace namespace, ParameterResolver parent) { this.namespace = namespace; this.parent = parent; }
Example #21
Source File: HibernateSessionExtension.java From judgels with GNU General Public License v2.0 | 4 votes |
private Store getStore(ExtensionContext context) { return context.getStore(Namespace.create(getClass(), context)); }
Example #22
Source File: ExtensionContextUtils.java From weld-junit with Apache License 2.0 | 3 votes |
/** * We use custom namespace based on this extension class; can be stored as static variable as it doesn't change throughout * testsuite execution. * * @param context {@link ExtensionContext} you are currently using * @return <b>Root</b> {@link ExtensionContext.Store} with {@link Namespace} based on extension class alone */ private static synchronized ExtensionContext.Store getRootExtensionStore(ExtensionContext context) { if (EXTENSION_NAMESPACE == null) { EXTENSION_NAMESPACE = Namespace.create(WeldJunit5Extension.class); } return context.getRoot().getStore(EXTENSION_NAMESPACE); }
Example #23
Source File: ExtensionContextUtils.java From weld-junit with Apache License 2.0 | 2 votes |
/** * We use custom namespace based on this extension class and test class, cannot be stored as static variable as test class * name changes throughout testsuite execution * * @param context {@link ExtensionContext} you are currently using * @return {@link ExtensionContext.Store} based on {@link ExtensionContext} and the required test class */ private static ExtensionContext.Store getTestStore(ExtensionContext context) { return context.getStore(Namespace.create(WeldJunit5Extension.class, context.getRequiredTestClass())); }
Example #24
Source File: JaasExtension.java From taskana with Apache License 2.0 | 2 votes |
/** * Gets the store with a <b>method-level</b> scope. * * @param context context for current extension * @return The store */ private Store getStore(ExtensionContext context) { return context.getStore(Namespace.create(getClass(), context.getRequiredTestMethod())); }