My testing method is failing. I'm not sure what to place in iterators place. Currently is null. How to test this when there is iterator?
Here is full main class which works, all it does is searching through array and returns index of the given number:
public class Main {
public static void main(String[] args) {
final List<Integer> numbers = Arrays.asList(3, 4, 6, 1, 9);
final Integer x = Integer.valueOf(1);
System.out.println(findSame(numbers.iterator(), x, 0));
}
public static final int findSame(Iterator<Integer> iterator, Integer x, int idx) {
if (!iterator.hasNext()) {
return -1;
}
if (iterator.next().equals(x)) {
return idx;
} else {
return findSame(iterator, x, idx+1);
}
}
}
Here is my testing trial method, which is not functional.
@Test
public void searchNumReturnsIndex1(){
Main instance = new Main();
System.out.println("Index");
Iterator<Integer> iterator = null;
int x = 6;
int expResult = 2;
int result = Main.findSame(iterator, x, 2);
assertEquals(expResult, result);
}
main()?main()?numbers. What isnumbers? A list. Do you have a list in your unit test?