本文整理匯總了Java中org.junit.jupiter.api.extension.ExtensionContext類的典型用法代碼示例。如果您正苦於以下問題:Java ExtensionContext類的具體用法?Java ExtensionContext怎麽用?Java ExtensionContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ExtensionContext類屬於org.junit.jupiter.api.extension包,在下文中一共展示了ExtensionContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleTestExecutionException
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
/**
* Handle the supplied {@code Throwable throwable}. If the {@code extensionContext} is annotated
* with {@link ExpectedException} and if the {@code throwable} matches the expectations expressed
* in the {@link ExpectedException} annotation then the supplied {@code throwable} is swallowed
* otherwise the supplied {@code throwable} is rethrown.
*
* @param extensionContext the current extension context
* @param throwable the {@code Throwable} to handle
* @throws Throwable
*/
@Override
public void handleTestExecutionException(ExtensionContext extensionContext, Throwable throwable)
throws Throwable {
Optional<ExpectedException> optional =
findAnnotation(extensionContext.getTestMethod(), ExpectedException.class);
if (optional.isPresent()) {
ExpectedException annotation = optional.get();
if (throwable.getClass() == annotation.type()) {
if (where(function, getPredicate(annotation)).test(throwable)) {
return;
}
}
}
throw throwable;
}
示例2: getOrCreateInjectorProvider
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
public static IInjectorProvider getOrCreateInjectorProvider(ExtensionContext context) {
InjectWith injectWith = context.getRequiredTestClass().getAnnotation(InjectWith.class);
if (injectWith != null) {
Class<? extends IInjectorProvider> klass = injectWith.value();
IInjectorProvider injectorProvider = injectorProviderClassCache.get(klass);
if (injectorProvider == null) {
try {
injectorProvider = klass.newInstance();
injectorProviderClassCache.put(klass, injectorProvider);
} catch (Exception e) {
throwUncheckedException(e);
}
}
return injectorProvider;
}
return null;
}
示例3: resolveParameter
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public Object resolveParameter(ParameterContext parameterContext,
ExtensionContext extensionContext)
throws ParameterResolutionException {
List<ParameterFactory> validFactories =
getSupportedFactories(parameterContext.getParameter()).collect(toList());
if (validFactories.size() > 1) {
throw new ParameterResolutionException(
String.format("Too many factories: %s for parameter: %s",
validFactories,
parameterContext.getParameter()));
}
return Iterables.getOnlyElement(validFactories)
.getParameterValue(parameterContext.getParameter());
}
示例4: handleTestExecutionException
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public void handleTestExecutionException(ExtensionContext context, Throwable throwable)
throws Throwable {
Optional<ExpectFailure> annotation = getAnnotation(context);
if (!annotation.isPresent()) {
throw throwable;
}
ExpectFailure expectedFailure = annotation.get();
context.getStore(NAMESPACE).put(expectedFailure, throwable);
ThrowableSubject subject = assertThat(throwable);
for (Cause cause : expectedFailure.value()) {
subject.isInstanceOf(cause.type());
if (!cause.message().isEmpty()) {
subject.hasMessageThat().contains(cause.message());
}
subject = subject.hasCauseThat();
}
}
示例5: getContextModuleTypes
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
/**
* Returns module types that are present on the given context or any of its enclosing contexts.
*/
private static Set<Class<? extends Module>> getContextModuleTypes(
Optional<ExtensionContext> context) {
// TODO: Cache?
Set<Class<? extends Module>> contextModuleTypes = new LinkedHashSet<>();
while (context.isPresent() && (hasAnnotatedElement(context) || hasParent(context))) {
context
.flatMap(ExtensionContext::getElement)
.map(GuiceExtension::getModuleTypes)
.ifPresent(contextModuleTypes::addAll);
context = context.flatMap(ExtensionContext::getParent);
}
return contextModuleTypes;
}
示例6: beforeAll
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public void beforeAll(ExtensionContext context) throws Exception {
Optional<String> baseUri = getProperty(BASE_URI_PROPERTY);
Optional<String> port = getProperty(DEPLOY_PORT_PROPERTY);
RestAssured.port = Integer.parseInt(port.orElse("8080"));
RestAssured.baseURI = baseUri.map(host -> "http://" + host).orElse(RestAssured.DEFAULT_URI);
RestAssured.rootPath = ROOT_PATH;
waitForIt(baseUri.orElse("localhost"), RestAssured.port);
}
示例7: afterTestExecution
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
IInjectorProvider injectorProvider = getOrCreateInjectorProvider(context);
if (injectorProvider instanceof IRegistryConfigurator) {
final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
registryConfigurator.restoreRegistry();
}
}
示例8: provideArguments
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public Stream<? extends Arguments> provideArguments(
ExtensionContext context) {
System.out.println("Arguments provider [2] to test "
+ context.getTestMethod().get().getName());
return Stream.of(Arguments.of("more", 3), Arguments.of("arguments", 4));
}
示例9: getMock
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
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));
}
}
示例10: handleTestExecutionException
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public void handleTestExecutionException(ExtensionContext context,
Throwable throwable) throws Throwable {
if (throwable instanceof IOException) {
return;
}
throw throwable;
}
開發者ID:PacktPublishing,項目名稱:Mastering-Software-Testing-with-JUnit-5,代碼行數:10,代碼來源:IgnoreIOExceptionExtension.java
示例11: getTestNameField
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
private Optional<Field> getTestNameField(ExtensionContext extensionContext) {
for (Field field : extensionContext.getRequiredTestClass().getDeclaredFields()) {
if (isAnnotated(field, TestName.class)) {
return Optional.of(field);
}
}
return Optional.empty();
}
示例12: afterAll
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public void afterAll(final ExtensionContext context) throws Exception {
final TestSetup testSetup = (TestSetup) context.getStore(NS).get(TestSetup.class);
if (testSetup != null) {
testSetup.shutdown();
}
}
示例13: beforeTestExecution
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public void beforeTestExecution(ExtensionContext context) throws Exception {
IInjectorProvider injectorProvider = getOrCreateInjectorProvider(context);
if (injectorProvider instanceof IRegistryConfigurator) {
final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
registryConfigurator.setupRegistry();
}
if (injectorProvider != null) {
Injector injector = injectorProvider.getInjector();
if (injector != null)
injector.injectMembers(context.getRequiredTestInstance());
}
}
示例14: beforeAll
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
@Override
public void beforeAll(ExtensionContext context) throws Exception {
if (!STARTED) {
out.println("Starting JavaFX");
Platform.startup(() -> {});
STARTED = true;
}
}
示例15: getMock
import org.junit.jupiter.api.extension.ExtensionContext; //導入依賴的package包/類
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));
}