UserDAO { public Optional<String> getHashedPassword(String name) { String r = dslContext .select(USERS.PASSWORD_HASH) .from(USERS) .where(USERS.USERNAME.eq(name)) .fetchOne(USERS.PASSWORD_HASH); return Optional.ofNullable(r); } UserDAO(DSLContext dslContext); Optional<String> getHashedPassword(String name); void createUserAt(String user, String password, OffsetDateTime created, OffsetDateTime updated); void createUser(String user, String password);  }
@Test public void getExistingUser() { String retrievedHash = userDAO.getHashedPassword("user").orElseThrow(RuntimeException::new); assertThat(retrievedHash).isEqualTo(hashedPassword); }
@Test public void getNonexistentUser() { assertThat(userDAO.getHashedPassword("non-user")).isEmpty(); }