1 package junitparams; 2 3 import static org.junit.Assert.assertEquals; 4 5 import java.util.*; 6 7 import org.junit.*; 8 import org.junit.runner.*; 9 10 @RunWith(JUnitParamsRunner.class) 11 public class IteratorMethodTest { 12 private static boolean firstCalled = false; 13 14 @Test 15 @Parameters shouldHandleIteratorsWithObject(String a)16 public void shouldHandleIteratorsWithObject(String a) { 17 assertEquals(1, a.length()); 18 if(a.equals("a")) firstCalled = true; 19 else assertEquals(firstCalled, true); 20 } 21 parametersForShouldHandleIteratorsWithObject()22 public Iterator<Object> parametersForShouldHandleIteratorsWithObject() { 23 ArrayList<Object> params = new ArrayList<Object>(); 24 params.add("a"); 25 params.add("b"); 26 return params.iterator(); 27 } 28 29 @Test 30 @Parameters shouldHandleIteratorsWithObjectArray(String a)31 public void shouldHandleIteratorsWithObjectArray(String a) { 32 assertEquals(1, a.length()); 33 if(a.equals("a")) firstCalled = true; 34 else assertEquals(firstCalled, true); 35 } 36 parametersForShouldHandleIteratorsWithObjectArray()37 public Iterator<Object[]> parametersForShouldHandleIteratorsWithObjectArray() { 38 ArrayList<Object[]> params = new ArrayList<Object[]>(); 39 params.add(new Object[]{"a"}); 40 params.add(new Object[]{"b"}); 41 return params.iterator(); 42 } 43 44 }