### Question:
StudentRepository { public Optional<Student> findByName(String name) { for (Student student : this.studentSet) { if (student.name.equals(name)) return Optional.of(student); } return Optional.empty(); } StudentRepository(Collection<Student> students); Optional<Student> findByName(String name);  }### Answer:
@Test public void whenStudentIsNotFoundThenReturnEmpty() { assertThat(studentRepository.findByName("Samantha")) .isNotPresent(); }
@Test public void whenStudentIsFoundThenReturnStudent() { assertThat(studentRepository.findByName("John")) .isPresent() .hasValueSatisfying(s -> { assertThat(s.name).isEqualTo("John"); assertThat(s.age).isEqualTo(21); }); }