BAEL-5889: Updated with review comment to add another method inside @Spy which is served through a mock to demonstrate partial mock condition

This commit is contained in:
balasr3
2023-09-23 16:11:32 +05:30
parent 14f336cf1a
commit f324a50165
8 changed files with 33 additions and 2 deletions
@@ -1,6 +1,7 @@
package com.baeldung.spytest;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Assertions;
@@ -23,6 +24,8 @@ class OrderServiceIntegrationTest {
void givenNotificationServiceIsUsingSpyBean_whenOrderServiceIsCalled_thenNotificationServiceSpyBeanShouldBeInvoked() {
Order orderInput = new Order(null, "Test", 1.0, "17 St Andrews Croft, Leeds ,LS17 7TP");
doReturn(true).when(notificationService)
.raiseAlert(any(Order.class));
Order order = orderService.save(orderInput);
Assertions.assertNotNull(order);
Assertions.assertNotNull(order.getId());
@@ -30,6 +30,8 @@ class OrderServiceUnitTest {
Order orderInput = new Order(orderId, "Test", 1.0, "17 St Andrews Croft, Leeds ,LS17 7TP");
doReturn(orderInput).when(orderRepository)
.save(any());
doReturn(true).when(notificationService)
.raiseAlert(any(Order.class));
Order order = orderService.save(orderInput);
Assertions.assertNotNull(order);
Assertions.assertEquals(orderId, order.getId());