- Added Test for '/email show' command.

- Update javadoc & cleanup.
This commit is contained in:
DNx5 2016-10-17 23:29:45 +07:00
parent b10b67b22f
commit b55805ff87
2 changed files with 79 additions and 7 deletions

View File

@ -5,21 +5,15 @@ import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.Management;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import java.util.List;
/**
* Created on 17/10/2016.
* Author: DNx
* Show email command.
*/
public class ShowEmailCommand extends PlayerCommand {
@Inject
private Management management;
@Inject
private CommandService commandService;

View File

@ -0,0 +1,78 @@
package fr.xephi.authme.command.executable.email;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.message.MessageKey;
import org.bukkit.entity.Player;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Test for {@link ShowEmailCommand}.
*/
@RunWith(MockitoJUnitRunner.class)
public class ShowEmailCommandTest {
private static final String CURRENT_EMAIL = "my.email@example.com";
private static final String USERNAME = "name";
@InjectMocks
private ShowEmailCommand command;
@Mock
private CommandService commandService;
@Mock
private PlayerCache playerCache;
@Test
public void shouldShowCurrentEmailMessage() {
// given
Player sender = mock(Player.class);
given(sender.getName()).willReturn(USERNAME);
given(playerCache.getAuth(USERNAME)).willReturn(newAuthWithEmail(CURRENT_EMAIL));
// when
command.executeCommand(sender, Collections.emptyList());
// then
verify(commandService).send(sender, MessageKey.EMAIL_SHOW, CURRENT_EMAIL);
}
@Test
public void shouldReturnNoEmailMessage() {
// given
Player sender = mock(Player.class);
given(sender.getName()).willReturn(USERNAME);
given(playerCache.getAuth(USERNAME)).willReturn(newAuthWithNoEmail());
// when
command.executeCommand(sender, Collections.emptyList());
// then
verify(commandService).send(sender, MessageKey.SHOW_NO_EMAIL);
}
private static PlayerAuth newAuthWithEmail(String email) {
return PlayerAuth.builder()
.name(USERNAME)
.email(email)
.build();
}
private static PlayerAuth newAuthWithNoEmail() {
return PlayerAuth.builder()
.name(USERNAME)
.build();
}
}