Why isn't this statement marked as completely covered by eclemma?
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
How about an ArrayList that has a value, and is therefore not empty?
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.
精彩评论