org.junit.jupiter.params.aggregator.ArgumentsAccessor Java Examples

The following examples show how to use org.junit.jupiter.params.aggregator.ArgumentsAccessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoteActionCodeTest.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
@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);
  }
}
 
Example #2
Source File: ArgumentAggregatorTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@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();
}
 
Example #3
Source File: ArgumentAggregatorTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@ParameterizedTest
@CsvSource({ "0" })
void testNoFactoryAccess_errors(ArgumentsAccessor arguments) {
	// would be nice to pass NoFactoryConverter...
	NoFactory nope = arguments.get(0, NoFactory.class);
	assertNotNull(nope);
}
 
Example #4
Source File: PersonUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@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());
}
 
Example #5
Source File: ArgumentAggregatorTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@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);
}
 
Example #6
Source File: ArgumentAggregatorTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public Object aggregateArguments(
		ArgumentsAccessor arguments, ParameterContext context) throws ArgumentsAggregationException {
	return Point.from(arguments.getDouble(1), arguments.getDouble(2));
}
 
Example #7
Source File: PersonAggregator.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public Object aggregateArguments(ArgumentsAccessor accessor, ParameterContext context)
        throws ArgumentsAggregationException {
    return new Person(accessor.getString(1), accessor.getString(2), accessor.getString(3));
}