public void testResultsHasSameElements(){
List()expectedResults=new ArrayList();
expectedResults.add("James");
expectedResults.add("Jack");
for(String name:customerNames){
assertEquals(name,expectedResult.get(0));
assertEquals(name,expectedResult.get(1));
}
}
If we look at the above testcase, it involves a lot of typing. We can simplify the above test using the fact that 2 Lists are equal if they contain the same objects at the same index. Another optimization which can be used is the Arrays.toList method to create the expectedResults list
The improved version of the test would look like
List()expectedResults=Arrays.asList(
new String[]{"James","Jack"}
);
new String[]{"James","Jack"}
);
assertEquals(customerNames,expectedResult);
}
}