下面列出了org.junit.jupiter.params.aggregator.ArgumentsAggregationException#org.junit.jupiter.params.aggregator.ArgumentsAccessor 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Method aggregateArguments(
final ArgumentsAccessor arguments, final ParameterContext context)
throws ArgumentsAggregationException {
// Ignore CSV columns that are already used by different parameters
final int offset = context.getIndex();
final Class<?> remoteInterface = arguments.get(offset, Class.class);
final String methodName = arguments.getString(offset + 1);
final Class<?>[] argumentTypes =
IntStream.range(offset + 2, arguments.size())
.mapToObj(i -> arguments.get(i, Class.class))
.toArray(Class<?>[]::new);
try {
return remoteInterface.getMethod(methodName, argumentTypes);
} catch (final NoSuchMethodException e) {
throw new ArgumentsAggregationException("Invalid method specified", e);
}
}
@ParameterizedTest
@CsvSource({ "0, 0, 0", "1, 0, 1", "1, 1, 0", "1.414, 1, 1", "2.236, 2, 1" })
// without ArgumentsAccessor in there, this leads to a ParameterResolutionException
void testEatingArguments(double norm, ArgumentsAccessor arguments, TestReporter reporter) {
reporter.publishEntry("norm", norm + "");
assertThat(norm).isNotNegative();
}
@ParameterizedTest
@CsvSource({ "0" })
void testNoFactoryAccess_errors(ArgumentsAccessor arguments) {
// would be nice to pass NoFactoryConverter...
NoFactory nope = arguments.get(0, NoFactory.class);
assertNotNull(nope);
}
@ParameterizedTest
@CsvSource({"Isaac,,Newton, Isaac Newton", "Charles,Robert,Darwin,Charles Robert Darwin"})
void fullName_ShouldGenerateTheExpectedFullName(ArgumentsAccessor argumentsAccessor) {
String firstName = argumentsAccessor.getString(0);
String middleName = (String) argumentsAccessor.get(1);
String lastName = argumentsAccessor.get(2, String.class);
String expectedFullName = argumentsAccessor.getString(3);
Person person = new Person(firstName, middleName, lastName);
assertEquals(expectedFullName, person.fullName());
}
@ParameterizedTest
@CsvSource({ "0, 0, 0", "1, 0, 1", "1, 1, 0", "1.414, 1, 1", "2.236, 2, 1" })
void testPointNorm(double norm, ArgumentsAccessor arguments) {
Point point = Point.from(arguments.getDouble(1), arguments.getDouble(2));
assertEquals(norm, point.norm(), 0.01);
}
@Override
public Object aggregateArguments(
ArgumentsAccessor arguments, ParameterContext context) throws ArgumentsAggregationException {
return Point.from(arguments.getDouble(1), arguments.getDouble(2));
}
@Override
public Object aggregateArguments(ArgumentsAccessor accessor, ParameterContext context)
throws ArgumentsAggregationException {
return new Person(accessor.getString(1), accessor.getString(2), accessor.getString(3));
}