Java Code Examples for org.junit.jupiter.api.extension.ExtensionContext.Store#getOrComputeIfAbsent()

The following examples show how to use org.junit.jupiter.api.extension.ExtensionContext.Store#getOrComputeIfAbsent() . 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: SpringExtension.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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.getRequiredTestClass();
	Store store = getStore(context);
	return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class);
}
 
Example 2
Source File: SpringExtension.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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.getRequiredTestClass();
	Store store = getStore(context);
	return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class);
}
 
Example 3
Source File: MockitoExtension.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
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 4
Source File: MockitoExtension.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
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 5
Source File: MockitoExtension.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 5 votes vote down vote up
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 6
Source File: MockitoExtension.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 5 votes vote down vote up
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 7
Source File: MockitoExtension.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
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: SpringExtension.java    From spring-test-junit5 with Apache License 2.0 5 votes vote down vote up
/**
 * 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.getRequiredTestClass();
	Store store = getStore(context);
	return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class);
}
 
Example 9
Source File: DBUnitExtension.java    From database-rider with Apache License 2.0 4 votes vote down vote up
/**
 * one test context (datasetExecutor, dbunitConfig etc..) per test
 */
private DBUnitTestContext getTestContext(ExtensionContext context) {
    Class<?> testClass = context.getRequiredTestClass();
    Store store = context.getStore(NAMESPACE);
    return store.getOrComputeIfAbsent(testClass, (tc) -> new DBUnitTestContext(), DBUnitTestContext.class);
}