private StartupForm getExampleStartupForm() { StartupForm startupForm = new StartupForm(); startupForm.setAdminLogin("admin"); startupForm.setAdminPassword("password"); startupForm.setAdminConfirmPassword("password"); startupForm.setAdminEmail("*****@*****.**"); return startupForm; }
@Test public void shouldRejectInvalidEmail() { PersistedUserValidator persistedUserValidator = new PersistedUserValidator(userService); StartupForm startupForm = getExampleStartupForm(); startupForm.setAdminEmail("admin@motech"); when(userService.hasUser("admin")).thenReturn(false); List<String> errors = new ArrayList<>(); persistedUserValidator.validate(startupForm, errors, ConfigSource.FILE); assertTrue(errors.contains("server.error.invalid.email")); }
@Test public void shouldRejectPasswordIfConfirmPasswordValueIsDifferent() { PersistedUserValidator persistedUserValidator = new PersistedUserValidator(userService); StartupForm startupForm = getExampleStartupForm(); startupForm.setAdminConfirmPassword("Password"); when(userService.hasUser("admin")).thenReturn(false); List<String> errors = new ArrayList<>(); persistedUserValidator.validate(startupForm, errors, ConfigSource.FILE); // If password is empty do not check against confirmPassword as empty password error is already // added assertTrue(errors.contains("server.error.invalid.password")); }