Reputation: 2991
I'm playing with Mockito (1.9.5) and stuck at first simple test case:
List mockedList = mock(ArrayList.class);
assertEquals(0, mockedList.size()); // Passed
assertTrue(mockedList.isEmpty()); // Failed
Can anyone explain why isEmpty() here returns false while the size() returns 0?
Upvotes: 10
Views: 4602
Reputation: 48265
I think this happens because mockito doesn't know the semantic meaning of isEmpty()
and when it encounters a boolean method mocks it with a default value that is false
. Same think happens with size()
but the default value here is 0
.
Basically, you need to define the expected behaviour of your mocked object. If you don't, it will return default values.
Upvotes: 17