Hi all,
I had some questions regarding use cases of new "Strict" stubbing.
With Junit5 & @ExtendWith(MockitoExtension.class) I've noticed that it errors out when I think it shouldn't (when compared with Junit4 & @RunWith(MockitoJUnitRunner.class) )
I have a very simple test case, which I consider to be both good code, and good mocking. Which gets highlighted as incorrect stubbing usage under Strict (default) checking
@Mock
private Map<String, Object> mockMap;
@Mock
private Object mockObject;
@Test
void testShouldReturnObjectsFromAMap() {
// When
when(mockMap.get("A")).thenReturn("Apple");
when(mockMap.get("B")).thenReturn(mockObject);
// Then
assertThat(mockMap.get("A")).isEqualTo("Apple");
assertThat(mockMap.get("B")).isEqualTo(mockObject);
}
The above generates the org.mockito.exceptions.misusing.PotentialStubbingProblem error.
This is a very common example of code in my company (which runs fine under the Junit4 runner)
What should I do with this? (I'd rather not D as we like Stricts' warnings normally!):
A) that's terrible code, why would you write that
B) that's not how you use Mockito
C) oh, that's something we overlooked, and will allow that in the next Mockito release
D) use Lenient().when().thenReturn();
E) something else
As it's my first post, and I don't want to appear like I've come in bashing. I'd like to add, I love Mockito, and we use it everywhere. Really appreciate the work you guys do