当前位置: 首页>>代码示例>>Java>>正文


Java ExtensionContext类代码示例

本文整理汇总了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;
}
 
开发者ID:glytching,项目名称:junit-extensions,代码行数:26,代码来源:ExpectedExceptionExtension.java

示例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;
}
 
开发者ID:Yakindu,项目名称:solidity-ide,代码行数:18,代码来源:InjectorProviders.java

示例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());
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:18,代码来源:MockitoExtension.java

示例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();
  }
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:22,代码来源:ExpectFailureExceptionHandler.java

示例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;
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:19,代码来源:GuiceExtension.java

示例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);
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:12,代码来源:RestExtension.java

示例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();
	}
}
 
开发者ID:Yakindu,项目名称:solidity-ide,代码行数:9,代码来源:InjectionExtension.java

示例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));
}
 
开发者ID:bonigarcia,项目名称:mastering-junit5,代码行数:10,代码来源:CustomArgumentsProvider2.java

示例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));
    }
}
 
开发者ID:bonigarcia,项目名称:mastering-junit5,代码行数:16,代码来源:MockitoExtension.java

示例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();
}
 
开发者ID:glytching,项目名称:junit-extensions,代码行数:9,代码来源:TestNameExtension.java

示例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();
    }

}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:9,代码来源:TestEEfi.java

示例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());
	}
}
 
开发者ID:Yakindu,项目名称:solidity-ide,代码行数:14,代码来源:InjectionExtension.java

示例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;
    }
}
 
开发者ID:testing-av,项目名称:testing-video,代码行数:9,代码来源:GenerateVideoExtension.java

示例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));
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:11,代码来源:MockitoExtension.java


注:本文中的org.junit.jupiter.api.extension.ExtensionContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。