本文整理汇总了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));
}