ObjectArrayConverter extends com.tngtech.junit.dataprovider.convert.ObjectArrayConverter { @Override public Object[] convert(Object[] data, boolean isVarargs, Class<?>[] parameterTypes) { return super.convert(data, isVarargs, parameterTypes); }  @Override Object[] convert(Object[] data, boolean isVarargs, Class<?>[] parameterTypes);  }
@Test public void testConvertShouldReturnSameObjectArrayWithoutVarargs() { Object[] data = new Object[] { 1 }; Class<?>[] parameterTypes = new Class<?>[] { int.class }; Object[] result = underTest.convert(data, false, parameterTypes); assertThat(result).isEqualTo(data); }
@Test public void testConvertShouldCreateEmptyVarargsArrayForMissingOnlyVarargsArgument() { Object[] data = new Object[0]; Class<?>[] parameterTypes = new Class<?>[] { int[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).containsExactly(new int[0]); }
@Test public void testConvertShouldHandleNullElementAsSingleElement() { Object[] data = new Object[] { null }; Class<?>[] parameterTypes = new Class<?>[] { String.class, int[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).containsExactly(null, new int[0]); }
@Test public void testConvertShouldCreateEmptyVarargsArrayForLastMissingVarargsArgument() { Object[] data = new Object[] { "test" }; Class<?>[] parameterTypes = new Class<?>[] { String.class, int[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).containsExactly("test", new int[0]); }
@Test public void testConvertShouldCreateVarargsArrayForOneOnlyVarargsArguments() { Object[] data = new Object[] { 1.0 }; Class<?>[] parameterTypes = new Class<?>[] { double[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).containsExactly(new double[] { 1.0 }); }
@Test public void testConvertShouldCreateVarargsArrayForOneLastVarargsArguments() { Object[] data = new Object[] { 'a', (byte) 2, 1.0 }; Class<?>[] parameterTypes = new Class<?>[] { char.class, byte.class, double[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).containsExactly('a', (byte) 2, new double[] { 1.0 }); }
@Test public void testConvertShouldCreateVarargsArrayForMultipleOnlyVarargsArguments() { Object[] data = new Object[] { 1l, 2l, 3l }; Class<?>[] parameterTypes = new Class<?>[] { long[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).containsExactly(new long[] { 1, 2, 3 }); }
@Test public void testConvertShouldCreateVarargsArrayForMultipleLastVarargsArguments() { Object[] data = new Object[] { "foobar", 1l, 2l, 3l }; Class<?>[] parameterTypes = new Class<?>[] { String.class, long[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).containsExactly("foobar", new long[] { 1, 2, 3 }); }
@Test public void testConvertShouldForwardArrayIfVarargsArrayIsAlreadyGivenForSingleArgument() { Object[] data = new Object[] { new String[] { "a", "z" } }; Class<?>[] parameterTypes = new Class<?>[] { String[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).isEqualTo(data); }
@Test public void testConvertShouldForwardArrayIfVarargsArrayIsAlreadyGivenForMultipleArguments() { Object[] data = new Object[] { 2, new boolean[] { false, true } }; Class<?>[] parameterTypes = new Class<?>[] { int.class, boolean[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).isEqualTo(data); }
@Test public void testConvertShouldForwardArrayIfVarargsIsArrayOfArray() { Object[] data = new Object[] { new int[][] { { 1, 2 }, { 3, 4 } } }; Class<?>[] parameterTypes = new Class<?>[] { int[][].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).isEqualTo(data); }
@Test public void testConvertShouldNotForwardArrayIfVarargsIsArrayOfArray() { Object[] data = new Object[] { new int[] { 1, 2 } }; Class<?>[] parameterTypes = new Class<?>[] { int[].class }; Object[] result = underTest.convert(data, true, parameterTypes); assertThat(result).isEqualTo(new int[][] { { 1, 2 } }); }