SingleArgConverter extends AbstractObjectConverter<Object> { @Override public Object[] convert(Object data, boolean isVarargs, Class<?>[] parameterTypes) { checkArgument(parameterTypes.length >= 1, "Object[] dataprovider must at least have a single argument for the dataprovider but found no parameters"); checkArgument(!isVarargs, "Object[] dataprovider does not support varargs"); Object[] result = new Object[] { data }; checkIfArgumentsMatchParameterTypes(result, parameterTypes); return result; }  @Override Object[] convert(Object data, boolean isVarargs, Class<?>[] parameterTypes);  }
@Test public void testConvertShouldThrowIllegalArgumentExceptionIfParameterTypesSizeIsZero() { Object data = 1; Class<?>[] parameterTypes = new Class<?>[] {}; expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Object[] dataprovider must at least have a single argument for the dataprovider but found no parameters"); underTest.convert(data, false, parameterTypes); }
@Test public void testConvertShouldReturnArgumentIfParameterTypesSizeIsEvenGreaterThanOne() { Object data = 2; Class<?>[] parameterTypes = new Class<?>[] { long.class, String.class, Long.class }; Object[] result = underTest.convert(data, false, parameterTypes); assertThat(result).containsExactly(data); }
@Test public void testConvertShouldThrowIllegalArgumentExceptionIfVarargsIsTrue() { Object data = 3.0; Class<?>[] parameterTypes = new Class<?>[] { double.class }; expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Object[] dataprovider does not support varargs"); underTest.convert(data, true, parameterTypes); }
@Test public void testConvertShouldWrapInputIntoArryAndReturnItIfPreconditionsMet() { Object data = "4"; Class<?>[] parameterTypes = new Class<?>[] { String.class }; Object[] result = underTest.convert(data, false, parameterTypes); assertThat(result).containsExactly("4"); }