1 package junitparams; 2 3 import static org.assertj.core.api.Assertions.assertThat; 4 5 import org.junit.*; 6 import org.junit.runner.*; 7 8 @RunWith(JUnitParamsRunner.class) 9 public class NullValuesTest { 10 11 private Object[] expectedSingleParams = new Object[]{null, "string", Long.valueOf(1)}; 12 13 private static int expectedSingleParamsIndex; 14 15 private Object[] expectedMultipleParams = multipleParams(); 16 private static int expectedMultipleParamsIndex; 17 18 @Test 19 @Parameters(method = "singleParams") passesForSingleParametersListWithTheWorkaround(Object param)20 public void passesForSingleParametersListWithTheWorkaround(Object param) { 21 assertThat(param).isEqualTo(expectedSingleParams[expectedSingleParamsIndex]); 22 expectedSingleParamsIndex++; 23 } 24 singleParams()25 public Object[] singleParams() { 26 return new Object[]{new Object[]{null}, "string", Long.valueOf(1)}; 27 } 28 29 @Test 30 @Parameters(method = "multipleParams") passesForMultipleParametersOutOfBox(Object param1, Object param2, Object param3)31 public void passesForMultipleParametersOutOfBox(Object param1, Object param2, Object param3) { 32 assertThat(param1).isEqualTo(((Object[]) expectedMultipleParams[expectedMultipleParamsIndex])[0]); 33 assertThat(param2).isEqualTo(((Object[]) expectedMultipleParams[expectedMultipleParamsIndex])[1]); 34 assertThat(param3).isEqualTo(((Object[]) expectedMultipleParams[expectedMultipleParamsIndex])[2]); 35 expectedMultipleParamsIndex++; 36 } 37 multipleParams()38 public Object[] multipleParams() { 39 return new Object[]{new Object[]{null, "string", null}, new Object[]{"string", Long 40 .valueOf(1), null}, new Object[]{null, null, null}}; 41 } 42 43 } 44