@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 '.*': .*"); }
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)); } }
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)); } }
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)); } return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); }
@BeforeEach public void prepare() { MockitoAnnotations.initMocks(this); when(extensionContext.getStore(Namespace.create(WatcherExtension.class, extensionContext))) .thenReturn(store); sut = new WatcherExtension(logger); }
@BeforeEach public void prepare() { MockitoAnnotations.initMocks(this); when(extensionContext.getStore( Namespace.create(TemporaryFolderExtension.class, extensionContext))) .thenReturn(store); }
private Object getMock(final Parameter parameter, final ExtensionContext extensionContext) { final Class<?> mockType = parameter.getType(); final Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType)); final String mockName = getMockName(parameter); return (mockName != null) ? mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)) : mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); }
private Store getStore(ExtensionContext context) { return context.getStore(Namespace.create(getClass(), context)); }
private ExtensionContext.Store getStore(ExtensionContext context) { return context.getStore(Namespace.create("de.aliceice.paper", getClass().getName())); }
private Store getStore(ExtensionContext context) { return context.getStore(Namespace.create(context.getRequiredTestMethod())); }
private Namespace localNamespace(ExtensionContext context) { return Namespace.create(TempDirectoryExtension.class, context); }
private static Store getMethodStore(ExtensionContext context) { Optional<Method> m = context.getTestMethod(); if (m.isPresent()) return context.getStore(Namespace.create(DatagenUtils.class, m.get())); return null; }
private static Store getClassStore(ExtensionContext context) { Optional<Class<?>> c = context.getTestClass(); if (c.isPresent()) return context.getStore(Namespace.create(DatagenUtils.class, c.get())); return null; }
ExtensionContextParamResolver(Namespace namespace, Class<?> first, Class<?>... others) { this(namespace, new EmptyResolver(), first, others); }
ExtensionContextParamResolver(Namespace namespace, ParameterResolver parent, Class<?> first, Class<?>... others) { this.namespace = namespace; this.parent = parent; this.parameterTypes = Lists.asList(first, others); }
/** * Creates a {@link Namespace} in which {@link ExtensionContext}s are stored on creation for post * execution restoration. Storing data in a custom namespace prevents accidental cross pollination * of data between extensions and between different invocations within the lifecycle of a single * extension. * * @param extensionContext the <em>context</em> in which the current test or container is being * executed * @return a {@link Namespace} describing the scope for a single {@link ExtensionContext} */ private Namespace namespace(ExtensionContext extensionContext) { return Namespace.create(this.getClass(), extensionContext); }
/** * Creates a {@link Namespace} in which {@link TemporaryFolder}s are stored on creation for post * execution destruction. Storing data in a custom namespace prevents accidental cross pollination * of data between extensions and between different invocations within the lifecycle of a single * extension. * * @param extensionContext the <em>context</em> in which the current test or container is being * executed * @return a {@link Namespace} describing the scope for a single {@link TemporaryFolder} */ private Namespace namespace(ExtensionContext extensionContext) { return Namespace.create(this.getClass(), extensionContext); }
/** * Creates a {@link Namespace} in which {@link RestoreContext}s are stored on creation for post * execution restoration. Storing data in a custom namespace prevents accidental cross pollination * of data between extensions and between different invocations within the lifecycle of a single * extension. * * @param extensionContext the <em>context</em> in which the current test or container is being * executed * @return a {@link Namespace} describing the scope for a single {@link RestoreContext} */ private Namespace namespace(ExtensionContext extensionContext) { return Namespace.create(this.getClass(), extensionContext); }