Rename DeliveryPlatform send method to 'deliver' to aid readability and avoiding confusion with EmailService.send method
Re-arrange order of mocks and inject mocks Rename argument matcher and captor tests
This commit is contained in:
parent
ab755bf098
commit
55d15037c0
|
@ -2,7 +2,7 @@ package com.baeldung.mockito.argumentcaptor;
|
|||
|
||||
public interface DeliveryPlatform {
|
||||
|
||||
void send(Email email);
|
||||
void deliver(Email email);
|
||||
|
||||
String getServiceStatus();
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ public class EmailService {
|
|||
}
|
||||
Email email = new Email(to, subject, body);
|
||||
email.setFormat(format);
|
||||
platform.send(email);
|
||||
platform.deliver(email);
|
||||
}
|
||||
|
||||
public ServiceStatus checkServiceStatus() {
|
||||
|
|
|
@ -10,12 +10,12 @@ import static org.junit.Assert.*;
|
|||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EmailServiceUnitTest {
|
||||
|
||||
@InjectMocks
|
||||
EmailService emailService;
|
||||
|
||||
@Mock
|
||||
DeliveryPlatform platform;
|
||||
|
||||
@InjectMocks
|
||||
EmailService emailService;
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<Email> emailCaptor;
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class EmailServiceUnitTest {
|
|||
|
||||
emailService.send(to, subject, body, false);
|
||||
|
||||
Mockito.verify(platform).send(emailCaptor.capture());
|
||||
Mockito.verify(platform).deliver(emailCaptor.capture());
|
||||
Email emailCaptorValue = emailCaptor.getValue();
|
||||
assertEquals(Format.TEXT_ONLY, emailCaptorValue.getFormat());
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class EmailServiceUnitTest {
|
|||
|
||||
emailService.send(to, subject, body, true);
|
||||
|
||||
Mockito.verify(platform).send(emailCaptor.capture());
|
||||
Mockito.verify(platform).deliver(emailCaptor.capture());
|
||||
Email value = emailCaptor.getValue();
|
||||
assertEquals(Format.HTML, value.getFormat());
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class EmailServiceUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void usingArgumentMatcher_whenAuthenticatedWithValidCredentials_expectTrue() {
|
||||
public void whenUsingArgumentMatcherForValidCredentials_expectTrue() {
|
||||
Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key");
|
||||
Mockito.when(platform.authenticate(Mockito.eq(credentials))).thenReturn(AuthenticationStatus.AUTHENTICATED);
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class EmailServiceUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void usingArgumentCaptor_whenAuthenticatedWithValidCredentials_expectTrue() {
|
||||
public void whenUsingArgumentCaptorForValidCredentials_expectTrue() {
|
||||
Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key");
|
||||
Mockito.when(platform.authenticate(credentialsCaptor.capture())).thenReturn(AuthenticationStatus.AUTHENTICATED);
|
||||
|
||||
|
|
Loading…
Reference in New Issue