Reputation: 585
I am using EclEmma in Eclipse (more specifically, RSA 8). I have the following statement in my code:
public static boolean isEmpty(Collection collection) {
return (collection == null) || collection.isEmpty();
}
and I have the following tests:
@Test public void isEmpty_nullCase() {
assertTrue(CollectionUtil.isEmpty(null));
}
@Test public void isEmpty_listCase() {
assertTrue(CollectionUtil.isEmpty(new ArrayList()));
}
but for some reason, the statement is showing up as yellow. What part of it am I not testing?
Thanks, Peter
Upvotes: 1
Views: 373
Reputation: 13161
Add the following test case:
@Test
public void checkNonNullNonEmpty(){
Assert.assertFalse(CollectionUtil.isEmpty(new ArrayList<String>(){
{
add("blah blah blah....!");
}
});
}
You have only tested true conditions. Ideally there are 4 possible combinations of return (collection == null) || collection.isEmpty();
statement. 1st condition can be T/F and 2nd can be T/F. So totall 4 possibilities. You have covered 3 only. The above test case will cover non null non empty possibility.
Upvotes: 0
Reputation: 156748
How about an ArrayList that has a value, and is therefore not empty?
Upvotes: 2