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?
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 isfalse. Same think happens withsize()but the default value here is0.Basically, you need to define the expected behaviour of your mocked object. If you don’t, it will return default values.