From 595aa8fe3bba0086f32031ac37d9d2ad20a0dfe0 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Tue, 9 Aug 2022 22:41:27 +0530 Subject: [PATCH] JAVA-13632 Updated code for Mocking Void Methods with Mockito --- .../argumentcaptor/EmailServiceUnitTest.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/testing-modules/mockito-simple/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java b/testing-modules/mockito-simple/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java index 5ed7be7d6e..c757a8bfb9 100644 --- a/testing-modules/mockito-simple/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java +++ b/testing-modules/mockito-simple/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java @@ -1,12 +1,18 @@ package com.baeldung.mockito.argumentcaptor; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.*; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import static org.junit.Assert.*; - @RunWith(MockitoJUnitRunner.class) public class EmailServiceUnitTest { @@ -32,7 +38,7 @@ public class EmailServiceUnitTest { Mockito.verify(platform).deliver(emailCaptor.capture()); Email emailCaptorValue = emailCaptor.getValue(); - assertEquals(Format.TEXT_ONLY, emailCaptorValue.getFormat()); + assertThat(emailCaptorValue.getFormat()).isEqualTo(Format.TEXT_ONLY); } @Test @@ -45,7 +51,7 @@ public class EmailServiceUnitTest { Mockito.verify(platform).deliver(emailCaptor.capture()); Email value = emailCaptor.getValue(); - assertEquals(Format.HTML, value.getFormat()); + assertThat(value.getFormat()).isEqualTo(Format.HTML); } @Test @@ -54,7 +60,7 @@ public class EmailServiceUnitTest { ServiceStatus serviceStatus = emailService.checkServiceStatus(); - assertEquals(ServiceStatus.UP, serviceStatus); + assertThat(serviceStatus).isEqualTo(ServiceStatus.UP); } @Test @@ -63,7 +69,7 @@ public class EmailServiceUnitTest { ServiceStatus serviceStatus = emailService.checkServiceStatus(); - assertEquals(ServiceStatus.DOWN, serviceStatus); + assertThat(serviceStatus).isEqualTo(ServiceStatus.DOWN); } @Test @@ -80,7 +86,7 @@ public class EmailServiceUnitTest { Mockito.when(platform.authenticate(credentialsCaptor.capture())).thenReturn(AuthenticationStatus.AUTHENTICATED); assertTrue(emailService.authenticatedSuccessfully(credentials)); - assertEquals(credentials, credentialsCaptor.getValue()); + assertThat(credentialsCaptor.getValue()).isEqualTo(credentials); } @Test