### Question:
EmailRegisterExecutor implements RegistrationExecutor<EmailRegisterParams> { @Override public boolean isRegistrationAdmitted(EmailRegisterParams params) { final int maxRegPerEmail = commonService.getProperty(EmailSettings.MAX_REG_PER_EMAIL); if (maxRegPerEmail > 0 && !commonService.hasPermission(params.getPlayer(), ALLOW_MULTIPLE_ACCOUNTS)) { int otherAccounts = dataSource.countAuthsByEmail(params.getEmail()); if (otherAccounts >= maxRegPerEmail) { commonService.send(params.getPlayer(), MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(maxRegPerEmail), Integer.toString(otherAccounts), "@"); return false; } } return true; }  @Override boolean isRegistrationAdmitted(EmailRegisterParams params); @Override PlayerAuth buildPlayerAuth(EmailRegisterParams params); @Override void executePostPersistAction(EmailRegisterParams params);  }### Answer:
@Test public void shouldNotPassEmailValidation() { given(commonService.getProperty(EmailSettings.MAX_REG_PER_EMAIL)).willReturn(3); String email = "test@example.com"; given(dataSource.countAuthsByEmail(email)).willReturn(4); Player player = mock(Player.class); EmailRegisterParams params = EmailRegisterParams.of(player, email); boolean result = executor.isRegistrationAdmitted(params); assertThat(result, equalTo(false)); verify(dataSource).countAuthsByEmail(email); verify(commonService).hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS); verify(commonService).send(player, MessageKey.MAX_REGISTER_EXCEEDED, "3", "4", "@"); }
@Test public void shouldPassVerificationForPlayerWithPermission() { given(commonService.getProperty(EmailSettings.MAX_REG_PER_EMAIL)).willReturn(3); Player player = mock(Player.class); given(commonService.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(true); EmailRegisterParams params = EmailRegisterParams.of(player, "test@example.com"); boolean result = executor.isRegistrationAdmitted(params); assertThat(result, equalTo(true)); verify(commonService).hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS); }
@Test public void shouldPassVerificationForPreviouslyUnregisteredIp() { given(commonService.getProperty(EmailSettings.MAX_REG_PER_EMAIL)).willReturn(1); String email = "test@example.com"; given(dataSource.countAuthsByEmail(email)).willReturn(0); Player player = mock(Player.class); EmailRegisterParams params = EmailRegisterParams.of(player, "test@example.com"); boolean result = executor.isRegistrationAdmitted(params); assertThat(result, equalTo(true)); verify(commonService).hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS); verify(dataSource).countAuthsByEmail(email); }