Update add email tests (#527)

This commit is contained in:
ljacqu 2016-02-19 19:26:16 +01:00
parent 5795b9d8fd
commit 964abdc0c5

View File

@ -56,16 +56,38 @@ public class AsyncAddEmailTest {
given(auth.getEmail()).willReturn(null);
given(playerCache.getAuth("tester")).willReturn(auth);
given(dataSource.isEmailStored("my.mail@example.org")).willReturn(false);
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(true);
// when
process.process();
// then
verify(dataSource).updateEmail(auth);
verify(messages).send(player, MessageKey.EMAIL_ADDED_SUCCESS);
verify(auth).setEmail("my.mail@example.org");
verify(playerCache).updatePlayer(auth);
}
@Test
public void shouldReturnErrorWhenMailCannotBeSaved() {
// given
AsyncAddEmail process = createProcess("my.mail@example.org");
given(player.getName()).willReturn("testEr");
given(playerCache.isAuthenticated("tester")).willReturn(true);
PlayerAuth auth = mock(PlayerAuth.class);
given(auth.getEmail()).willReturn(null);
given(playerCache.getAuth("tester")).willReturn(auth);
given(dataSource.isEmailStored("my.mail@example.org")).willReturn(false);
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(false);
// when
process.process();
// then
verify(dataSource).updateEmail(auth);
verify(messages).send(player, MessageKey.ERROR);
}
@Test
public void shouldNotAddMailIfPlayerAlreadyHasEmail() {
// given