-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
10 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class UserRegistrationTest { | ||
|
@@ -58,7 +57,9 @@ public void shouldAddNewUserToDatabaseUsingAnyMatcherTypedOutside() throws UserA | |
} | ||
|
||
@Test | ||
public void shouldAddNewUserToDatabaseUsingAnyMatcherTypedInside() throws UserAlreadyRegisteredException, IOException { | ||
public void shouldAddNewUserToDatabase() throws UserAlreadyRegisteredException, IOException { | ||
UserRegistration testee = new UserRegistration(mockDatabase, mockEmailSender); | ||
|
||
String emailAddress = "[email protected]"; | ||
when(mockDatabase.hasUser(emailAddress)).thenReturn(false); | ||
|
||
|
@@ -71,13 +72,13 @@ public void shouldAddNewUserToDatabaseUsingAnyMatcherTypedInside() throws UserAl | |
} | ||
|
||
@Test(expected = UserAlreadyRegisteredException.class) | ||
public void shouldThrowExceptionAddingEmailAddressWhenUserAlreadyRegistered() throws UserAlreadyRegisteredException, EmailFailedException { | ||
/* | ||
* Both of these are functionally equivalent in this example | ||
Mockito.when(mockDatabase.hasUser(anyString())).thenReturn(true); | ||
Mockito.doReturn(true).when(mockDatabase).hasUser(anyString()); | ||
*/ | ||
Mockito.doReturn(true).when(mockDatabase).hasUser(anyString()); | ||
public void shouldThrowExceptionAddingDuplicateEmail() throws UserAlreadyRegisteredException, EmailFailedException { | ||
Database mockDatabase = Mockito.mock(Database.class); | ||
EmailSender mockEmailSender = Mockito.mock(EmailSender.class); | ||
|
||
UserRegistration testee = new UserRegistration(mockDatabase, mockEmailSender); | ||
|
||
Mockito.when(mockDatabase.hasUser("[email protected]")).thenReturn(true); | ||
testee.registerNewUser("[email protected]"); | ||
} | ||
|
||
|