@Test public void testImportStudents() throws Exception { // Given StudentDirectoryServiceImpl studentDirectoryService = new StudentDirectoryServiceImpl(); StudentDAO studentDAO = mock(StudentDAO.class); studentDirectoryService.setStudentDAO(studentDAO); MultipartFile multipartFile = mock(MultipartFile.class); StringBuffer buffer = new StringBuffer(); buffer.append("Bart, Simpson\n"); buffer.append("Lisa, Simpson"); InputStream stream = new ByteArrayInputStream(buffer.toString().getBytes(StandardCharsets.UTF_8)); when(multipartFile.getInputStream()).thenReturn(stream); // When studentDirectoryService.importStudents(multipartFile); // Then ArgumentCaptor<Student> studentCaptor = ArgumentCaptor.forClass(Student.class); verify(studentDAO, times(2)).createStudent(studentCaptor.capture()); assertEquals("Bart", studentCaptor.getAllValues().get(0).getFirstName()); assertEquals("Simpson", studentCaptor.getAllValues().get(0).getLastName()); assertEquals("Lisa", studentCaptor.getAllValues().get(1).getFirstName()); assertEquals("Simpson", studentCaptor.getAllValues().get(1).getLastName()); }
@Override public String toString( boolean qOption, boolean hOption, boolean tOption, List<StorageType> types) { if (tOption) { StringBuffer result = new StringBuffer(); result.append(hOption ? HUMAN : BYTES); for (StorageType type : types) { result.append(type.toString()); result.append(" "); } return result.toString(); } if (qOption) { if (hOption) { return (HUMAN + WITH_QUOTAS); } else { return (BYTES + WITH_QUOTAS); } } else { if (hOption) { return (HUMAN + NO_QUOTAS); } else { return (BYTES + NO_QUOTAS); } } }