• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ConvertWith类的典型用法和代码示例

java 1次浏览

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

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

示例1: resolveParameter

点赞 3

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的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: isAtLeast

点赞 3

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ParameterizedTest
@CsvSource({
	"JRE_VERSION_9,   JRE_VERSION_160, true",
	"JRE_VERSION_9,   JRE_VERSION_170, true",
	"JRE_VERSION_9,   JRE_VERSION_180, true",
	"JRE_VERSION_9,   JRE_VERSION_9,   true",
	"JRE_VERSION_180, JRE_VERSION_160, true",
	"JRE_VERSION_180, JRE_VERSION_170, true",
	"JRE_VERSION_180, JRE_VERSION_180, true",
	"JRE_VERSION_170, JRE_VERSION_160, true",
	"JRE_VERSION_170, JRE_VERSION_170, true",
	"JRE_VERSION_180, JRE_VERSION_9,   false",
	"JRE_VERSION_170, JRE_VERSION_180, false",
	"JRE_VERSION_170, JRE_VERSION_9,   false",
})
public void isAtLeast(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version1,
		@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version2, boolean result) {
	assertEquals(version1.isAtLeast(version2), result);
}
 

开发者ID:kaikramer,
项目名称:keystore-explorer,
代码行数:20,
代码来源:JavaVersionTest.java

示例3: isBelow

点赞 3

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ParameterizedTest
@CsvSource({
	"JRE_VERSION_160, JRE_VERSION_170, true",
	"JRE_VERSION_170, JRE_VERSION_180, true",
	"JRE_VERSION_180, JRE_VERSION_9,   true",
	"JRE_VERSION_9,   JRE_VERSION_180, false",
	"JRE_VERSION_170, JRE_VERSION_160, false",
	"JRE_VERSION_170, JRE_VERSION_170, false",
	"JRE_VERSION_180, JRE_VERSION_160, false",
	"JRE_VERSION_180, JRE_VERSION_170, false",
	"JRE_VERSION_180, JRE_VERSION_180, false",
})
public void isBelow(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version1,
		@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version2, boolean result) {
	assertEquals(version1.isBelow(version2), result);
}
 

开发者ID:kaikramer,
项目名称:keystore-explorer,
代码行数:17,
代码来源:JavaVersionTest.java

示例4: testWithExplicitArgumentConversion

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ParameterizedTest
@EnumSource(TimeUnit.class)
void testWithExplicitArgumentConversion(
        @ConvertWith(CustomArgumentsConverter.class) String argument) {
    System.out.println("Argument " + argument + " is a type of "
            + argument.getClass());

    assertNotNull(argument);
}
 

开发者ID:bonigarcia,
项目名称:mastering-junit5,
代码行数:10,
代码来源:ExplicitConversionParameterizedTest.java

示例5: anySuperclass

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ParameterizedTest
@ValueSource(strings = {
    "java.util.List",
    "java.util.Collection",
    "java.lang.Object",
})
void anySuperclass(
    @ConvertWith(ClassArgumentConverter.class) Class<? super List<?>> superclassOfList) {
  assertThat(superclassOfList).isNotNull();
}
 

开发者ID:JeffreyFalgout,
项目名称:junit5-extensions,
代码行数:11,
代码来源:UsageExampleTests.java

示例6: anySubclass

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ParameterizedTest
@ValueSource(strings = {
    "java.util.List",
    "java.util.ArrayList",
})
void anySubclass(@ConvertWith(ClassArgumentConverter.class) Class<? extends List<?>> anything) {
  assertThat(anything).isNotNull();
}
 

开发者ID:JeffreyFalgout,
项目名称:junit5-extensions,
代码行数:9,
代码来源:UsageExampleTests.java

示例7: classNotFound

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(type = ArgumentConversionException.class),
    @Cause(type = ClassNotFoundException.class)
})
@ParameterizedTest
@ValueSource(strings = "123ClassDoesNotExist")
void classNotFound(@ConvertWith(ClassArgumentConverter.class) Class<?> clazz) {}
 

开发者ID:JeffreyFalgout,
项目名称:junit5-extensions,
代码行数:9,
代码来源:UsageExampleTests.java

示例8: badParameterType

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(type = ArgumentConversionException.class, message = "Invalid parameter type")
})
@ParameterizedTest
@ValueSource(strings = "java.lang.Object")
void badParameterType(@ConvertWith(ClassArgumentConverter.class) String clazz) {}
 

开发者ID:JeffreyFalgout,
项目名称:junit5-extensions,
代码行数:8,
代码来源:UsageExampleTests.java

示例9: wrongClass

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(
        type = ArgumentConversionException.class,
        message = "java.lang.Class<java.util.List> is not assignable to"
            + " java.lang.Class<java.util.Collection<?>>"
    )
})
@ParameterizedTest
@ValueSource(strings = "java.util.List")
void wrongClass(@ConvertWith(ClassArgumentConverter.class) Class<Collection<?>> clazz) {}
 

开发者ID:JeffreyFalgout,
项目名称:junit5-extensions,
代码行数:12,
代码来源:UsageExampleTests.java

示例10: badLowerBound

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(type = ArgumentConversionException.class, message = "is not assignable to")
})
@ParameterizedTest
@ValueSource(strings = "java.util.List")
void badLowerBound(
    @ConvertWith(ClassArgumentConverter.class) Class<? super Collection<?>> clazz) {}
 

开发者ID:JeffreyFalgout,
项目名称:junit5-extensions,
代码行数:9,
代码来源:UsageExampleTests.java

示例11: badUpperBound

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(type = ArgumentConversionException.class, message = "is not assignable to")
})
@ParameterizedTest
@ValueSource(strings = "java.lang.Object")
void badUpperBound(
    @ConvertWith(ClassArgumentConverter.class) Class<? extends Collection<?>> clazz) {}
 

开发者ID:JeffreyFalgout,
项目名称:junit5-extensions,
代码行数:9,
代码来源:UsageExampleTests.java

示例12: equals

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ParameterizedTest
@CsvSource({
	"JRE_VERSION_160, 1.6.0",
	"JRE_VERSION_170, 1.7.0",
	"JRE_VERSION_180, 1.8.0",
})
public void equals(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion verConst, String verStr) {
	assertEquals(verConst, new JavaVersion(verStr));
}
 

开发者ID:kaikramer,
项目名称:keystore-explorer,
代码行数:10,
代码来源:JavaVersionTest.java

示例13: compareTo

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ParameterizedTest
@CsvSource({
	"JRE_VERSION_160, 1.6.0_45, 0",
	"JRE_VERSION_170, 1.6.0_45, 1",
	"JRE_VERSION_170, 1.7.0_101, 0",
	"JRE_VERSION_180, 1.7.0_101, 1",
	"JRE_VERSION_180, 1.8.0_20, 0",
	"JRE_VERSION_170, 1.8.0_20, -1",
	"JRE_VERSION_160, 1.8.0_20, -1",
})
public void compareTo(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion verConst, String verStr,
		int result) {
	assertEquals(Integer.signum(verConst.compareTo(new JavaVersion(verStr))), result);
}
 

开发者ID:kaikramer,
项目名称:keystore-explorer,
代码行数:15,
代码来源:JavaVersionTest.java

示例14: testPointNotNull_1

点赞 2

import org.junit.jupiter.params.converter.ConvertWith; //导入依赖的package包/类
@ParameterizedTest
@ValueSource(strings = { "(0/0)", "(0/1)", "(1/0)", "(1/1)", "(2/1)" })
void testPointNotNull_1(@ConvertWith(PointConverter.class) Point point) {
	assertNotNull(point);
}
 

开发者ID:CodeFX-org,
项目名称:demo-junit-5,
代码行数:6,
代码来源:CustomArgumentConverterTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)