Execution implements AutoCloseable { public Map<String, Object> createReport() { Map<String, Object> report = new LinkedHashMap<>(); if (name != null) { report.put("Task", name); } for (Entry<String, ?> p : parameters.entrySet()) { report.put("Parameter[" + p.getKey() + "]", p.getValue()); } DateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); if (stats.isStopped()) { report.put("Status", "finished"); report.put("Duration", stats.getDuration()); } else { report.put("Status", "in progress"); report.put("Started on ", format.format(new Date(stats.getStarted()))); } report.put("Extracted", stats.getExtracted()); report.put("Created", stats.getCreated()); report.put("Updated", stats.getUpdated()); report.put("Deleted", stats.getDeleted()); return report; } Execution(String name, Map<String, ?> params); @Override void close(); @Override String toString(); String getName(); Map<String, Object> createReport(); Object getAttribute(String key); void setAttribute(String key, Object value); Map<String, ?> getParameters(); ExecutionStats getStats();  }
@Test public void testCreateReport() { Execution execution = new Execution("xsync", Collections.singletonMap("a", 5)); Map<String, Object> r1 = execution.createReport(); assertEquals("xsync", r1.get("Task")); assertEquals(5, r1.get("Parameter[a]")); assertEquals(8, r1.size(), r1.toString()); assertEquals("in progress", r1.get("Status")); execution.getStats().incrementCreated(5); execution.getStats().incrementDeleted(4); execution.getStats().incrementExtracted(55); execution.getStats().incrementUpdated(3); execution.close(); Map<String, Object> r2 = execution.createReport(); assertEquals(8, r2.size(), r2.toString()); assertEquals("finished", r2.get("Status")); assertEquals(55L, r2.get("Extracted")); assertEquals(5L, r2.get("Created")); assertEquals(4L, r2.get("Deleted")); assertEquals(3L, r2.get("Updated")); }