Java 类org.junit.jupiter.api.extension.ExtensionContext.Store 实例源码

项目:junit5-extensions    文件:GuiceExtension.java   
/**
 * Returns an injector for the given context if and only if the given context has an {@link
 * ExtensionContext#getElement() annotated element}.
 */
private static Optional<Injector> getOrCreateInjector(ExtensionContext context)
    throws NoSuchMethodException,
    InstantiationException,
    IllegalAccessException,
    InvocationTargetException {
  if (!context.getElement().isPresent()) {
    return Optional.empty();
  }

  AnnotatedElement element = context.getElement().get();
  Store store = context.getStore(NAMESPACE);

  Injector injector = store.get(element, Injector.class);
  if (injector == null) {
    injector = createInjector(context);
    store.put(element, injector);
  }

  return Optional.of(injector);
}
项目:GitToolBox    文件:IdeaMocksExtension.java   
@Override
public void beforeEach(ExtensionContext context) {
  IdeaMocksImpl ideaMocks = new IdeaMocksImpl();
  Project project = mock(Project.class);
  MessageBus messageBus = mock(MessageBus.class);
  when(project.getMessageBus()).thenReturn(messageBus);
  when(messageBus.syncPublisher(any(Topic.class))).thenAnswer(invocation -> {
    Topic topic = invocation.getArgument(0);
    Class<?> listenerClass = topic.getListenerClass();
    if (ideaMocks.hasMockListener(listenerClass)) {
      return ideaMocks.getMockListener(listenerClass);
    } else {
      return ideaMocks.mockListener(listenerClass);
    }
  });

  Store store = context.getStore(NS);
  store.put(Project.class, project);
  store.put(MessageBus.class, messageBus);
  store.put(IdeaMocks.class, ideaMocks);
}
项目:qpp-conversion-tool    文件:MockitoExtension.java   
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));
    }
}
项目:mastering-junit5    文件:MockitoExtension.java   
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));
    }
}
项目:mastering-junit5    文件:MockitoExtension.java   
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));
    }
}
项目:intellij-spring-assistant    文件:MockitoExtension.java   
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));
  }
}
项目:open-kilda    文件:MockitoExtension.java   
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));
}
项目:selenium-jupiter    文件:MockitoExtension.java   
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));
    }
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MockitoExtension.java   
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));
    }
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MockitoExtension.java   
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));
    }
}
项目:vertx-acme4j    文件:MockitoExtension.java   
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));
    }
}
项目:database-rider    文件:DBUnitExtension.java   
/**
 * one test context (datasetExecutor, dbunitConfig etc..) per test
 */
private DBUnitTestContext getTestContext(ExtensionContext context) {
    Class<?> testClass = context.getTestClass().get();
    Store store = context.getStore(namespace);
    DBUnitTestContext testContext = store.get(testClass, DBUnitTestContext.class);
    if (testContext == null) {
        testContext = new DBUnitTestContext();
        store.put(testClass, testContext);
    }
    return testContext;
}
项目:logbook-kai-plugins    文件:MockitoExtension.java   
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));
    }
}
项目:kata-botwars    文件:MockitoExtension.java   
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));
    }
}
项目:Lyrics    文件:MockitoExtension.java   
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));
    }
}
项目:Lyrics    文件:MockitoExtension.java   
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));
    }
}
项目:triplea    文件:MockitoExtension.java   
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));
}
项目:junit5-samples    文件:MockitoExtension.java   
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));
    }
}
项目:spring-test-junit5    文件:SpringExtension.java   
/**
 * 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);
}
项目:GitToolBox    文件:PlatformTestCaseExtension.java   
private void runSetup(ExtensionContext context) throws Exception {
  if (runInDispatchThread()) {
    TestRunnerUtil.replaceIdeEventQueueSafely();
    EdtTestUtil.runInEdtAndWait(this::setUp);
  } else {
    setUp();
  }
  Store store = getStore(context);
  store.put(Project.class, getProject());
  store.put(Module.class, getModule());
}
项目:GitToolBox    文件:PlatformTestCaseExtension.java   
private void runTearDown(ExtensionContext context) throws Exception {
  if (runInDispatchThread()) {
    EdtTestUtil.runInEdtAndWait(this::tearDown);
  } else {
    tearDown();
  }
  Store store = getStore(context);
  store.remove(Project.class);
  store.remove(Module.class);
}
项目:GitToolBox    文件:IdeaMocksExtension.java   
@Override
public void afterEach(ExtensionContext context) {
  Store store = context.getStore(NS);
  store.remove(Project.class);
  store.remove(MessageBus.class);
  store.remove(IdeaMocks.class);
}
项目:GitToolBox    文件:MockitoExtension.java   
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));
  }
}
项目:junit-dataprovider    文件:AbstractUseDataProviderArgumentProvider.java   
/**
 * Retrieves the test data from given dataprovider method.
 *
 * @param dataProviderMethod the dataprovider method that gives the parameters; never {@code null}
 * @param cacheDataProviderResult determines if the dataprovider result should be cached using
 *            {@code dataProviderMethod} as key
 * @param context the execution context to use to create a {@link TestInfo} if required; never {@code null}
 *
 * @return a list of methods, each method bound to a parameter combination returned by the dataprovider
 * @throws NullPointerException if and only if one of the given arguments is {@code null}
 */
protected Object invokeDataProviderMethodToRetrieveData(Method dataProviderMethod, boolean cacheDataProviderResult,
        ExtensionContext context) {
    checkNotNull(dataProviderMethod, "'dataProviderMethod' must not be null");
    checkNotNull(context, "'context' must not be null");

    Store store = context.getRoot().getStore(NAMESPACE_USE_DATAPROVIDER);

    Object cached = store.get(dataProviderMethod);
    if (cached != null) {
        return cached;
    }
    try {
        // TODO how to not require junit-jupiter-engine dependency and reuse already existing ExtensionRegistry?
        ExtensionRegistry extensionRegistry = createRegistryWithDefaultExtensions(emptyConfigurationParameters());
        Object data = executableInvoker.invoke(dataProviderMethod, context.getTestInstance().orElse(null), context,
                extensionRegistry);
        if (cacheDataProviderResult) {
            store.put(dataProviderMethod, data);
        }
        return data;

    } catch (Exception e) {
        throw new ParameterResolutionException(
                String.format("Exception while invoking dataprovider method '%s': %s", dataProviderMethod.getName(),
                        e.getMessage()),
                e);
    }
}
项目:junit-dataprovider    文件:UseDataProviderInvocationContextProvider.java   
/**
 * Retrieves the test data from given dataprovider method.
 *
 * @param dataProviderMethod the dataprovider method that gives the parameters; never {@code null}
 * @param cacheDataProviderResult determines if the dataprovider result should be cached using
 *            {@code dataProviderMethod} as key
 * @param context the execution context to use to create a {@link TestInfo} if required; never {@code null}
 *
 * @return a list of methods, each method bound to a parameter combination returned by the dataprovider
 * @throws NullPointerException if and only if one of the given arguments is {@code null}
 */
protected Object invokeDataProviderMethodToRetrieveData(Method dataProviderMethod, boolean cacheDataProviderResult,
        ExtensionContext context) {
    checkNotNull(dataProviderMethod, "'dataProviderMethod' must not be null");
    checkNotNull(context, "'context' must not be null");

    Store store = context.getRoot().getStore(NAMESPACE_USE_DATAPROVIDER);

    Object cached = store.get(dataProviderMethod);
    if (cached != null) {
        return cached;
    }
    try {
        // TODO how to not require junit-jupiter-engine dependency and reuse already existing ExtensionRegistry?
        ExtensionRegistry extensionRegistry = createRegistryWithDefaultExtensions(emptyConfigurationParameters());
        Object data = executableInvoker.invoke(dataProviderMethod, context.getTestInstance().orElse(null), context,
                extensionRegistry);
        if (cacheDataProviderResult) {
            store.put(dataProviderMethod, data);
        }
        return data;

    } catch (Exception e) {
        throw new ParameterResolutionException(
                String.format("Exception while invoking dataprovider method '%s': %s", dataProviderMethod.getName(),
                        e.getMessage()),
                e);
    }
}
项目:mastering-junit5    文件:TimingExtension.java   
private Store getStore(ExtensionContext context) {
    return context.getStore(Namespace.create(getClass(), context));
}
项目:golden-master    文件:RunInvocationContextProvider.java   
private Store getStore(ExtensionContext context) {
    return context.getStore(NAMESPACE);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:TimingExtension.java   
private Store getStore(ExtensionContext context) {
    return context.getStore(Namespace.create(getClass(), context));
}
项目:junit5-demo    文件:TimingExtension.java   
private Store getStore(ExtensionContext context) {
    return context.getStore(Namespace.create(context.getRequiredTestMethod()));
}
项目:datagen    文件:DatagenUtils.java   
private static void putSeedToStoreIfAbsent(ExtensionContext context, Long seed) {
    Store store = getStore(context);
    if(store != null) store.put("seed", seed);
}
项目:datagen    文件:DatagenUtils.java   
private static Long getCurrentLevelSeedFromStore(ExtensionContext context) {
    Store store = getStore(context);
    Object seed = null;
    if(store != null) seed = store.get("seed");
    return seed != null ? (Long) seed : null;
}
项目:datagen    文件:DatagenUtils.java   
private static Store getStore(ExtensionContext context) {
    Store store = getMethodStore(context);
    if(store == null) store = getClassStore(context);
    return store;
}
项目:datagen    文件:DatagenUtils.java   
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;
}
项目:datagen    文件:DatagenUtils.java   
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;
}
项目:spring-test-junit5    文件:SpringExtension.java   
private static Store getStore(ExtensionContext context) {
    return context.getRoot().getStore(NAMESPACE);
}
项目:GitToolBox    文件:PlatformTestCaseExtension.java   
private Store getStore(ExtensionContext context) {
  return context.getStore(NS);
}
项目:junit-extensions    文件:WatcherExtension.java   
/**
 * Creates a {@link Store} for a {@link ExtensionContext} in the context of the given {@code
 * extensionContext}. A {@link Store} is bound to an {@link ExtensionContext} so different test
 * invocations do not share the same store. For example a test invocation on {@code
 * ClassA.testMethodA} will have a different {@link Store} instance to that associated with a test
 * invocation on {@code ClassA.testMethodB} or test invocation on {@code ClassC.testMethodC}.
 *
 * @param extensionContext the <em>context</em> in which the current test or container is being
 *     executed
 * @return a {@link Store} for the given {@code extensionContext}
 */
private Store getStore(ExtensionContext extensionContext) {
  return extensionContext.getStore(namespace(extensionContext));
}
项目:junit-extensions    文件:TemporaryFolderExtension.java   
/**
 * Creates a {@link Store} for a {@link TemporaryFolder} in the context of the given {@code
 * extensionContext}. A {@link Store} is bound to an {@link ExtensionContext} so different test
 * invocations do not share the same store. For example a test invocation on {@code
 * ClassA.testMethodA} will have a different {@link Store} instance to that associated with a test
 * invocation on {@code ClassA.testMethodB} or test invocation on {@code ClassC.testMethodC}.
 *
 * @param extensionContext the <em>context</em> in which the current test or container is being
 *     executed
 * @return a {@link Store} for the given {@code extensionContext}
 */
private Store getStore(ExtensionContext extensionContext) {
  return extensionContext.getStore(namespace(extensionContext));
}
项目:junit-extensions    文件:SystemPropertyExtension.java   
/**
 * Creates a {@link Store} for a {@link RestoreContext} in the context of the given {@code
 * extensionContext}. A {@link Store} is bound to an {@link ExtensionContext} so different test
 * invocations do not share the same store. For example a test invocation on {@code
 * ClassA.testMethodA} will have a different {@link Store} instance to that associated with a test
 * invocation on {@code ClassA.testMethodB} or test invocation on {@code ClassC.testMethodC}.
 *
 * @param extensionContext the <em>context</em> in which the current test or container is being
 *     executed
 * @return a {@link Store} for the given {@code extensionContext}
 */
private Store getStore(ExtensionContext extensionContext) {
  return extensionContext.getRoot().getStore(namespace(extensionContext));
}