### Question:
ArchiveWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { String archive = (String) workItem.getParameter("Archive"); List<File> files = (List<File>) workItem.getParameter("Files"); try { RequiredParameterValidator.validate(this.getClass(), workItem); OutputStream outputStream = new FileOutputStream(new File(archive)); ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("tar", outputStream); if (files != null) { for (File file : files) { final TarArchiveEntry entry = new TarArchiveEntry("testdata/test1.xml"); entry.setModTime(0); entry.setSize(file.length()); entry.setUserId(0); entry.setGroupId(0); entry.setMode(0100000); os.putArchiveEntry(entry); IOUtils.copy(new FileInputStream(file), os); } } os.closeArchiveEntry(); os.close(); manager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { handleException(e); manager.abortWorkItem(workItem.getId()); } }  void executeWorkItem(WorkItem workItem,
                                WorkItemManager manager); void abortWorkItem(WorkItem workItem,
                              WorkItemManager manager);  }### Answer:
@Test public void testNoFilesSpecified() { TestWorkItemManager manager = new TestWorkItemManager(); WorkItemImpl workItem = new WorkItemImpl(); workItem.setParameter("Archive", "testfile.txt"); workItem.setParameter("Files", new ArrayList<File>()); ArchiveWorkItemHandler archiveWorkItemHandler = new ArchiveWorkItemHandler(); archiveWorkItemHandler.setLogThrownException(true); archiveWorkItemHandler.executeWorkItem(workItem, manager); assertEquals(1, manager.getAbortedWorkItems().size()); assertTrue(manager.getAbortedWorkItems().contains(workItem.getId())); }
@Test public void testWithTempFile() throws Exception { TestWorkItemManager manager = new TestWorkItemManager(); WorkItemImpl workItem = new WorkItemImpl(); workItem.setId(123L); File tempFile = tempFolder.newFile("tempFile1.txt"); FileUtils.writeStringToFile(tempFile, "temp file content", "UTF-8"); File tempFileTwo = tempFolder.newFile("tempFile2.txt"); FileUtils.writeStringToFile(tempFileTwo, "temp file2 content", "UTF-8"); List<java.io.File> filesList = new ArrayList<>(); filesList.add(tempFile); filesList.add(tempFileTwo); workItem.setParameter("Archive", "testfile.txt"); workItem.setParameter("Files", filesList); ArchiveWorkItemHandler archiveWorkItemHandler = new ArchiveWorkItemHandler(); archiveWorkItemHandler.setLogThrownException(true); archiveWorkItemHandler.executeWorkItem(workItem, manager); assertNotNull(manager.getResults()); assertEquals(1, manager.getResults().size()); assertTrue(manager.getResults().containsKey(workItem.getId())); }
@Test public void testNoArchiveSpecified() throws Exception { TestWorkItemManager manager = new TestWorkItemManager(); WorkItemImpl workItem = new WorkItemImpl(); workItem.setParameter("Files", new ArrayList<File>()); ArchiveWorkItemHandler archiveWorkItemHandler = new ArchiveWorkItemHandler(); archiveWorkItemHandler.setLogThrownException(true); archiveWorkItemHandler.executeWorkItem(workItem, manager); assertEquals(1, manager.getAbortedWorkItems().size()); assertTrue(manager.getAbortedWorkItems().contains(workItem.getId())); }