@Test public void testDeleteStudent_passnull() { // Given StudentDirectoryServiceImpl studentDirectoryService = new StudentDirectoryServiceImpl(); try { // When studentDirectoryService.deactivateStudent(null); fail("An exception should have been thrown for a null value passed as a parameter."); } catch (Exception e) { // Then assertTrue(e instanceof NullPointerException); assertEquals("Unable to deactivate a student. The student cannot be null.", e.getMessage()); } }
@Test public void testDeactivateStudent_happypath() { // Given StudentDirectoryServiceImpl studentDirectoryService = new StudentDirectoryServiceImpl(); StudentDAO studentDAO = mock(StudentDAO.class); studentDirectoryService.setStudentDAO(studentDAO); Student testStudent = new Student(); testStudent.setFirstName("Michael"); testStudent.setLastName("Bluth"); // When studentDirectoryService.deactivateStudent(testStudent); // Then ArgumentCaptor<Student> studentCaptor = ArgumentCaptor.forClass(Student.class); verify(studentDAO, times(1)).updateStudent(studentCaptor.capture()); assertEquals("Michael", studentCaptor.getValue().getFirstName()); assertEquals("Bluth", studentCaptor.getValue().getLastName()); assertFalse(studentCaptor.getValue().getActive()); }