### Question:
TaskPersisterJpa implements TaskPersister { @Override public String createTask(String taskType, Map<String, Object> taskConfig) { String id = Strings.randomBase64UUID(); TaskStatusInfo t = new TaskStatusInfo(); t.setId(id); t.setTaskType(taskType); t.setTaskCreatedAt(new Date()); t.setTaskStatus(TaskStatus.NEW); t.setTaskConfig(taskConfig); em.persist(t); return id; } TaskPersisterJpa(); @Override String createTask(String taskType, Map<String, Object> taskConfig); @Override List<TaskStatusInfo> listTasks(String taskTypeFilter, List<TaskStatus> taskStatusFilter, int from, int size); @Override TaskStatusInfo getTaskStatusInfo(String id); @Override boolean markTaskToBeCancelled(String id); @Override boolean changeTaskStatus(String id, TaskStatus taskStatusNew, String message); @Override void writeTaskLog(String id, String message); @Override TaskStatusInfo getTaskToRun(String nodeId); @Override void heartbeat(String nodeId, Set<String> runningTasksId, long failoverTimeout); static final long FAILOVER_DELAY_10; static final long FAILOVER_DELAY_30; static final long FAILOVER_DELAY_100; }### Answer:
@Test public void createTask() { TaskPersisterJpa tested = getTested(); final String taskType = "tt"; final Map<String, Object> taskConfig = new HashMap<String, Object>(); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { TaskStatusInfo actual = (TaskStatusInfo) invocation.getArguments()[0]; Assert.assertNotNull(actual.getId()); TestUtils.assertCurrentDate(actual.getTaskCreatedAt()); Assert.assertEquals(TaskStatus.NEW, actual.getTaskStatus()); Assert.assertEquals(taskType, actual.getTaskType()); TestUtils.assertJsonContent(taskConfig, actual.getTaskConfig()); return null; } }).when(tested.em).persist(Mockito.any(TaskStatusInfo.class)); Assert.assertNotNull(tested.createTask(taskType, taskConfig)); Mockito.verify(tested.em).persist(Mockito.any(TaskStatusInfo.class)); }