-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
apache/kafka
#12460Description
Hi,
I am using mockito-core 4.5.1 and JUnit 5. I can use MockitoExtension
and @Mock
annotation and by default I get Strict Stubbing behaviour. However, if I use Mockito.Mock(MyClass.class)
to create mock it seems Strictness is not enabled. Even if I stub unnecessary methods it is not giving any error.
I know I can work around this by using MockitoExtension to create mocks using @mock, but is there any way to enable Strict Stubbing while using Mockito.mock(MyClass.class);
class ProductServiceTest {
private ProductRepository productRepository;
private ProductService productService;
@BeforeEach
void setUp() {
productRepository = Mockito.mock(ProductRepository.class);
productService = new ProductService(productRepository);
// this is unnecessary method stubbing but it is not giving any error
Mockito.when(productRepository.findAllActiveProducts()).thenReturn(List.of());
}
@Test
void shouldReturnOnlyActiveProducts() {
BDDMockito.given(productRepository.findAll()).willReturn(List.of(p1, p2));
productService.findAll(); // which calls productRepository.findAll()
}
}
dplavcic
Metadata
Metadata
Assignees
Labels
No labels