Search in sources :

Example 1 with Store

use of org.junit.jupiter.api.extension.ExtensionContext.Store in project spring-framework by spring-projects.

the class DisabledIfConditionTestCase method buildExtensionContext.

// -------------------------------------------------------------------------
private TestExtensionContext buildExtensionContext(String methodName) {
    Class<?> testClass = SpringTestCase.class;
    Method method = ReflectionUtils.findMethod(getClass(), methodName);
    Store store = mock(Store.class);
    when(store.getOrComputeIfAbsent(any(), any(), any())).thenReturn(new TestContextManager(testClass));
    TestExtensionContext extensionContext = mock(TestExtensionContext.class);
    when(extensionContext.getTestClass()).thenReturn(Optional.of(testClass));
    when(extensionContext.getElement()).thenReturn(Optional.of(method));
    when(extensionContext.getStore(any())).thenReturn(store);
    return extensionContext;
}
Also used : Store(org.junit.jupiter.api.extension.ExtensionContext.Store) Method(java.lang.reflect.Method) TestContextManager(org.springframework.test.context.TestContextManager) TestExtensionContext(org.junit.jupiter.api.extension.TestExtensionContext)

Example 2 with Store

use of org.junit.jupiter.api.extension.ExtensionContext.Store in project spring-framework by spring-projects.

the class SpringExtension method getTestContextManager.

/**
	 * Get the {@link TestContextManager} associated with the supplied {@code ExtensionContext}.
	 * @return the {@code TestContextManager} (never {@code null})
	 */
private static TestContextManager getTestContextManager(ExtensionContext context) {
    Assert.notNull(context, "ExtensionContext must not be null");
    Class<?> testClass = context.getTestClass().get();
    Store store = context.getStore(NAMESPACE);
    return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class);
}
Also used : Store(org.junit.jupiter.api.extension.ExtensionContext.Store) TestContextManager(org.springframework.test.context.TestContextManager)

Aggregations

Store (org.junit.jupiter.api.extension.ExtensionContext.Store)2 TestContextManager (org.springframework.test.context.TestContextManager)2 Method (java.lang.reflect.Method)1 TestExtensionContext (org.junit.jupiter.api.extension.TestExtensionContext)1