예제 #1
0
  @Test
  public void shouldRejectEmailIfInUse() {
    PersistedUserValidator persistedUserValidator = new PersistedUserValidator(userService);

    when(userService.hasUser("admin")).thenReturn(false);
    UserDto user = new UserDto();
    user.setUserName("john");
    when(userService.hasEmail("*****@*****.**")).thenReturn(true);

    List<String> errors = new ArrayList<>();
    persistedUserValidator.validate(getExampleStartupForm(), errors, ConfigSource.FILE);

    assertTrue(errors.contains("server.error.email.exist"));
  }
예제 #2
0
  @Test
  public void shouldRejectOnlyUserIfUserExistsAndIsRegisteredWithIdenticalEmail() {
    PersistedUserValidator persistedUserValidator = new PersistedUserValidator(userService);

    when(userService.hasUser("admin")).thenReturn(true);

    UserDto userDto = new UserDto();
    userDto.setUserName("admin");
    when(userService.hasEmail("*****@*****.**")).thenReturn(true);

    List<String> errors = new ArrayList<>();
    persistedUserValidator.validate(getExampleStartupForm(), errors, ConfigSource.FILE);

    assertTrue(errors.contains("server.error.user.exist"));
    assertFalse(errors.contains("server.error.email.exist"));
  }