package io.caster.mockito;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import static org.mockito.ArgumentMatchers.anyString;

public class UserRegistrationTest {

    private UserRegistration testee;

    private Database mockDatabase;

    @Before
    public void setup() {
        mockDatabase = Mockito.mock(Database.class);

        testee = new UserRegistration(mockDatabase);
    }

    @Test (expected = UserAlreadyRegisteredException.class)
    public void shouldThrowExceptionWhenUserAlreadyRegistered() throws UserAlreadyRegisteredException {
        Mockito.when(mockDatabase.hasUser(anyString())).thenReturn(true);
        testee.registerNewUser("foo@example.com");
    }
}
@@ -580,16 +580,17 @@
 ption %7B%0A
+%0A
         
@@ -651,24 +651,25 @@
 turn(true);%0A
+%0A
         test
@@ -712,10 +712,345 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void shouldAddNewUserToDatabase() throws UserAlreadyRegisteredException %7B%0A        String emailAddress = %22foo@example.com%22;%0A        Mockito.when(mockDatabase.hasUser(emailAddress)).thenReturn(false);%0A%0A        testee.registerNewUser(emailAddress);%0A%0A        Mockito.verify(mockDatabase).addUser(emailAddress);%0A    %7D
 %0A%7D

add unit test showing an example of .verify acting on a mock object