### Question:
AsyncRegister implements AsynchronousProcess { public <P extends RegistrationParameters> void register(RegistrationMethod<P> variant, P parameters) { if (preRegisterCheck(parameters.getPlayer())) { RegistrationExecutor<P> executor = registrationExecutorFactory.getSingleton(variant.getExecutorClass()); if (executor.isRegistrationAdmitted(parameters)) { executeRegistration(parameters, executor); } } } AsyncRegister(); void register(RegistrationMethod<P> variant, P parameters);  }### Answer:
@Test public void shouldDetectAlreadyLoggedInPlayer() { String name = "robert"; Player player = mockPlayerWithName(name); given(playerCache.isAuthenticated(name)).willReturn(true); RegistrationExecutor executor = mock(RegistrationExecutor.class); singletonStoreWillReturn(registrationExecutorStore, executor); asyncRegister.register(RegistrationMethod.PASSWORD_REGISTRATION, PasswordRegisterParams.of(player, "abc", null)); verify(commonService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); verifyZeroInteractions(dataSource, executor); }
@Test public void shouldStopForDisabledRegistration() { String name = "albert"; Player player = mockPlayerWithName(name); given(playerCache.isAuthenticated(name)).willReturn(false); given(commonService.getProperty(RegistrationSettings.IS_ENABLED)).willReturn(false); RegistrationExecutor executor = mock(RegistrationExecutor.class); singletonStoreWillReturn(registrationExecutorStore, executor); asyncRegister.register(RegistrationMethod.TWO_FACTOR_REGISTRATION, TwoFactorRegisterParams.of(player)); verify(commonService).send(player, MessageKey.REGISTRATION_DISABLED); verifyZeroInteractions(dataSource, executor); }
@Test public void shouldStopForAlreadyRegisteredName() { String name = "dilbert"; Player player = mockPlayerWithName(name); given(playerCache.isAuthenticated(name)).willReturn(false); given(commonService.getProperty(RegistrationSettings.IS_ENABLED)).willReturn(true); given(dataSource.isAuthAvailable(name)).willReturn(true); RegistrationExecutor executor = mock(RegistrationExecutor.class); singletonStoreWillReturn(registrationExecutorStore, executor); asyncRegister.register(RegistrationMethod.TWO_FACTOR_REGISTRATION, TwoFactorRegisterParams.of(player)); verify(commonService).send(player, MessageKey.NAME_ALREADY_REGISTERED); verify(dataSource, only()).isAuthAvailable(name); verifyZeroInteractions(executor); }
@Test @SuppressWarnings("unchecked") public void shouldStopForFailedExecutorCheck() { String name = "edbert"; Player player = mockPlayerWithName(name); TestHelper.mockPlayerIp(player, "33.44.55.66"); given(playerCache.isAuthenticated(name)).willReturn(false); given(commonService.getProperty(RegistrationSettings.IS_ENABLED)).willReturn(true); given(commonService.getProperty(RestrictionSettings.MAX_REGISTRATION_PER_IP)).willReturn(0); given(dataSource.isAuthAvailable(name)).willReturn(false); RegistrationExecutor executor = mock(RegistrationExecutor.class); TwoFactorRegisterParams params = TwoFactorRegisterParams.of(player); given(executor.isRegistrationAdmitted(params)).willReturn(false); singletonStoreWillReturn(registrationExecutorStore, executor); asyncRegister.register(RegistrationMethod.TWO_FACTOR_REGISTRATION, params); verify(dataSource, only()).isAuthAvailable(name); verify(executor, only()).isRegistrationAdmitted(params); }