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


Java ParameterContext类代码示例

本文整理汇总了Java中org.junit.jupiter.api.extension.ParameterContext的典型用法代码示例。如果您正苦于以下问题:Java ParameterContext类的具体用法?Java ParameterContext怎么用?Java ParameterContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ParameterContext类属于org.junit.jupiter.api.extension包,在下文中一共展示了ParameterContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
        throws ParameterResolutionException {
    Object argument = arguments[parameterContext.getIndex()];
    Parameter parameter = parameterContext.getParameter();
    Optional<ConvertWith> annotation = AnnotationUtils.findAnnotation(parameter, ConvertWith.class);
    // @formatter:off
    ArgumentConverter argumentConverter = annotation.map(ConvertWith::value)
            .map(clazz -> (ArgumentConverter) ReflectionUtils.newInstance(clazz))
            .map(converter -> AnnotationConsumerInitializer.initialize(parameter, converter))
            .orElse(DefaultArgumentConverter.INSTANCE);
    // @formatter:on
    try {
        return argumentConverter.convert(argument, parameterContext);
    } catch (Exception ex) {
        throw new ParameterResolutionException("参数转换出错:" + parameter.getType().getName(),
                ex);
    }
}
 
开发者ID:ychaoyang,项目名称:autotest,代码行数:20,代码来源:AutoTestParameterResolver.java

示例2: resolveParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的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

示例3: resolve

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
//  public AbstractVaadinPageObject resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
  public AbstractVaadinPageObject resolve(ParameterContext parameterContext, ExtensionContext extensionContext)
      throws ParameterResolutionException {

    Supplier<WebDriver> webDriverSupplier = webdriver().apply(extensionContext);

    Class<?> pageObject = parameterContext.getParameter().getType();
    try {
      Constructor<?> constructor =
          pageObject.getConstructor(WebDriver.class);
      return AbstractVaadinPageObject.class.cast(constructor.newInstance(webDriverSupplier.get()));
    } catch (NoSuchMethodException
        | IllegalAccessException
        | InstantiationException
        | InvocationTargetException e) {
      e.printStackTrace();
      throw new ParameterResolutionException("was not able to create PageObjectInstance ", e);
    }
  }
 
开发者ID:Java-Publications,项目名称:vaadin-016-helloworld-14,代码行数:21,代码来源:PageObjectExtension.java

示例4: parameterContextOf

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
private static ParameterContext parameterContextOf(final Parameter parameter) {
    return new ParameterContext() {
        @Override
        public Parameter getParameter() {
            return parameter;
        }

        @Override
        public int getIndex() {
            return 0;
        }

        @Override
        public Optional<Object> getTarget() {
            return Optional.empty();
        }
    };
}
 
开发者ID:fyodor-org-uk,项目名称:fyodor,代码行数:19,代码来源:SupportedTemporalityParametersTest.java

示例5: resolveParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
    // we did our checks in supportsParameter() method, now we can do simple resolution
    if (getContainerFromStore(extensionContext) != null) {
        List<Annotation> qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager());
        return getContainerFromStore(extensionContext)
            .select(parameterContext.getParameter().getType(), qualifiers.toArray(new Annotation[qualifiers.size()])).get();
    }
    return null;
}
 
开发者ID:weld,项目名称:weld-junit,代码行数:11,代码来源:WeldJunit5Extension.java

示例6: supportsParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
    // if weld container isn't up yet or if its not Method, we don't resolve it
    if (getContainerFromStore(extensionContext) == null || (!(parameterContext.getDeclaringExecutable() instanceof Method))) {
        return false;
    }
    List<Annotation> qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager());
    // if we require explicit parameter injection (via global settings or annotation) and there are no qualifiers we don't resolve it
    if ((getExplicitInjectionInfoFromStore(extensionContext) || (methodRequiresExplicitParamInjection(parameterContext))) && qualifiers.isEmpty()) {
        return false;
    } else {
        return getContainerFromStore(extensionContext).select(parameterContext.getParameter().getType(), qualifiers.toArray(new Annotation[qualifiers.size()]))
            .isResolvable();
    }
}
 
开发者ID:weld,项目名称:weld-junit,代码行数:16,代码来源:WeldJunit5Extension.java

示例7: resolveQualifiers

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
private List<Annotation> resolveQualifiers(ParameterContext pc, BeanManager bm) {
    List<Annotation> qualifiers = new ArrayList<>();
    if (pc.getParameter().getAnnotations().length == 0) {
        return Collections.emptyList();
    } else {
        for (Annotation annotation : pc.getParameter().getAnnotations()) {
            // use BeanManager.isQualifier to be able to detect custom qualifiers which don't need to have @Qualifier
            if (bm.isQualifier(annotation.annotationType())) {
                qualifiers.add(annotation);
            }
        }
    }
    return qualifiers;
}
 
开发者ID:weld,项目名称:weld-junit,代码行数:15,代码来源:WeldJunit5Extension.java

示例8: methodRequiresExplicitParamInjection

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
private boolean methodRequiresExplicitParamInjection(ParameterContext pc) {
    for (Annotation annotation : pc.getDeclaringExecutable().getAnnotations()) {
        if (annotation.annotationType().equals(ExplicitParamInjection.class)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:weld,项目名称:weld-junit,代码行数:9,代码来源:WeldJunit5Extension.java

示例9: convert

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object convert(Object input, ParameterContext context) throws ArgumentConversionException {
  TypeToken<?> parameterType = TypeToken.of(context.getParameter().getParameterizedType());
  if (parameterType.getRawType() != Class.class) {
    throw new ArgumentConversionException(
        String.format("Could not convert: %s. Invalid parameter type.", input));
  }

  return convert(input.toString(), (TypeToken<? extends Class<?>>) parameterType);
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:12,代码来源:ClassArgumentConverter.java

示例10: supportsParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public boolean supportsParameter(ParameterContext parameterContext,
    ExtensionContext extensionContext)
    throws ParameterResolutionException {
  Parameter parameter = parameterContext.getParameter();
  if (getBindingAnnotations(parameter).size() > 1) {
    return false;
  }

  Key<?> key = getKey(
      extensionContext.getTestClass(),
      parameter);
  Optional<Injector> optInjector = getInjectorForParameterResolution(extensionContext);
  return optInjector.map(injector -> injector.getExistingBinding(key)).isPresent();
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:16,代码来源:GuiceExtension.java

示例11: resolveParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public Object resolveParameter(ParameterContext parameterContext,
    ExtensionContext extensionContext)
    throws ParameterResolutionException {
  Parameter parameter = parameterContext.getParameter();
  Key<?> key = getKey(extensionContext.getTestClass(), parameter);
  Injector injector = getInjectorForParameterResolution(extensionContext)
      .orElseThrow(() ->
          new ParameterResolutionException(
              String.format(
                  "Could not create injector for: %s It has no annotated element.",
                  extensionContext.getDisplayName())));

  return injector.getInstance(key);
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:16,代码来源:GuiceExtension.java

示例12: supportsParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public boolean supportsParameter(ParameterContext parameterContext,
        ExtensionContext extensionContext) {
    Class<?> type = parameterContext.getParameter().getType();
    return (WebDriver.class.isAssignableFrom(type) && !type.isInterface())
            || type.equals(List.class);
}
 
开发者ID:bonigarcia,项目名称:selenium-jupiter,代码行数:8,代码来源:SeleniumExtension.java

示例13: resolveParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public ApplicationConfiguration resolveParameter(
    ParameterContext parameterContext,
    ExtensionContext extensionContext
) throws ParameterResolutionException {
    return getConfiguration();
}
 
开发者ID:alphagov,项目名称:verify-matching-service-adapter,代码行数:8,代码来源:ApplicationConfigurationResolver.java

示例14: resolveParameter

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public FilesLocator resolveParameter(
    ParameterContext parameterContext,
    ExtensionContext extensionContext
) throws ParameterResolutionException {
    if (applicationFilesLocator == null) {
        applicationFilesLocator = new ScenarioFilesLocator(null);
    }

    return applicationFilesLocator;
}
 
开发者ID:alphagov,项目名称:verify-matching-service-adapter,代码行数:12,代码来源:FilesLocatorResolver.java

示例15: resolve

import org.junit.jupiter.api.extension.ParameterContext; //导入依赖的package包/类
@Override
public Object resolve(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
    if (extensionContext.getTestClass().isPresent()) {
        CasePack pack = extensionContext.getTestClass().get().getAnnotation(CasePack.class);
        return pack.value();
    }
    return null;
}
 
开发者ID:MegafonWebLab,项目名称:histone-java2,代码行数:9,代码来源:StringParamResolver.java


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