#427 Make email option for /register [pass] [email] variant

This commit is contained in:
ljacqu 2016-12-27 15:37:52 +01:00
parent dfad0211b7
commit e905ff3013
3 changed files with 9 additions and 5 deletions

View File

@ -75,7 +75,7 @@ public class RegisterCommand extends PlayerCommand {
RegistrationArgumentType registrationType = commonService.getProperty(REGISTRATION_TYPE); RegistrationArgumentType registrationType = commonService.getProperty(REGISTRATION_TYPE);
if (registrationType == PASSWORD_WITH_CONFIRMATION && !arguments.get(0).equals(arguments.get(1))) { if (registrationType == PASSWORD_WITH_CONFIRMATION && !arguments.get(0).equals(arguments.get(1))) {
commonService.send(player, MessageKey.PASSWORD_MATCH_ERROR); commonService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
} else if (registrationType == PASSWORD_WITH_EMAIL) { } else if (registrationType == PASSWORD_WITH_EMAIL && arguments.size() > 1) {
handlePasswordWithEmailRegistration(player, arguments); handlePasswordWithEmailRegistration(player, arguments);
} else { } else {
management.performRegister(player, registrationExecutorProvider management.performRegister(player, registrationExecutorProvider

View File

@ -20,7 +20,7 @@ public enum RegistrationArgumentType {
EMAIL_WITH_CONFIRMATION(Execution.EMAIL, 2, MessageKey.REGISTER_EMAIL_MESSAGE), EMAIL_WITH_CONFIRMATION(Execution.EMAIL, 2, MessageKey.REGISTER_EMAIL_MESSAGE),
/** /register [password] [email] */ /** /register [password] [email] */
PASSWORD_WITH_EMAIL(Execution.PASSWORD, 2, MessageKey.REGISTER_PASSWORD_EMAIL_MESSAGE); PASSWORD_WITH_EMAIL(Execution.PASSWORD, 1, MessageKey.REGISTER_PASSWORD_EMAIL_MESSAGE);
private final Execution execution; private final Execution execution;
private final int requiredNumberOfArgs; private final int requiredNumberOfArgs;

View File

@ -27,6 +27,8 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -276,17 +278,19 @@ public class RegisterCommandTest {
} }
@Test @Test
public void shouldFailForInsufficientArguments() { public void shouldPerformNormalPasswordRegisterForOneArgument() {
// given // given
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)) given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE))
.willReturn(RegistrationArgumentType.PASSWORD_WITH_EMAIL); .willReturn(RegistrationArgumentType.PASSWORD_WITH_EMAIL);
Player player = mock(Player.class); Player player = mock(Player.class);
RegistrationExecutor executor = mock(RegistrationExecutor.class);
given(registrationExecutorProvider.getPasswordRegisterExecutor(eq(player), anyString())).willReturn(executor);
// when // when
command.executeCommand(player, Collections.singletonList("myPass")); command.executeCommand(player, Collections.singletonList("myPass"));
// then // then
verify(commonService).send(player, MessageKey.USAGE_REGISTER); verify(registrationExecutorProvider).getPasswordRegisterExecutor(player, "myPass");
verifyZeroInteractions(management); verify(management).performRegister(player, executor);
} }
} }