Skip to content

Commit

Permalink
Minor tidy up of example tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CDRussell committed Mar 30, 2017
1 parent d2d1d7b commit 6e6e326
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/src/test/java/io/caster/mockito/UserRegistrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand All @@ -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]");
}

Expand Down

0 comments on commit 6e6e326

Please sign in to comment.