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:
+3
@@ -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());
|
||||
|
||||
+2
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user