當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。