### Question:
AdminUserValidator { public void validateAdminUserId(UUID userId) throws InvalidDtoException { if (userId == null) { throw new InvalidDtoException("Id not set."); } checkIdForSemanticExceptions(userId); } @Autowired  AdminUserValidator(UserService userService, AdminUserRepository adminUserRepository); void validateAdminUserOnAdd(AdminUser user); void validateAdminUserId(UUID userId);  }### Answer:
@Test public void validateAdminUserId_idIsNull_expectedThrow() { try { adminUserValidator.validateAdminUserId(null); fail("Should throw InvalidDtoException."); } catch (Exception ex) { assertThat( "Should only throw InvalidDtoException.", ex, instanceOf(InvalidDtoException.class)); } verify(adminUserRepository, never()).findById(null); }
@Test public void validateAdminUserId_adminIsCurrentUser_expectedThrow() { try { adminUserValidator.validateAdminUserId(currentUserId); fail("Should throw InvalidDtoException."); } catch (Exception ex) { assertThat( "Should only throw InvalidDtoException", ex, instanceOf(InvalidDtoException.class)); } verify(userService).getCurrentUser(); verify(userService, never()).doesUserExist(currentUserId); }
@Test public void validateAdminUserId_adminIsNotInUserList_expectedThrow() { UUID uuid = UUID.randomUUID(); try { adminUserValidator.validateAdminUserId(uuid); fail("Should throw InvalidDtoException."); } catch (Exception ex) { assertThat( "Should only throw InvalidDtoException", ex, instanceOf(InvalidDtoException.class)); } verify(userService).getCurrentUser(); verify(userService).doesUserExist(uuid); }
@Test public void validateAdminUserId_validAdminUser_expectedNoThrow() throws InvalidDtoException { adminUserValidator.validateAdminUserId(userToInsertId); }