DynamicTaskMapper implements TaskMapper { @VisibleForTesting String getDynamicTaskName(Map<String, Object> taskInput, String taskNameParam) throws TerminateWorkflowException { return Optional.ofNullable(taskInput.get(taskNameParam)) .map(String::valueOf) .orElseThrow(() -> { String reason = String.format("Cannot map a dynamic task based on the parameter and input. " + "Parameter= %s, input= %s", taskNameParam, taskInput); return new TerminateWorkflowException(reason); }); } DynamicTaskMapper(ParametersUtils parametersUtils, MetadataDAO metadataDAO); @Override List<Task> getMappedTasks(TaskMapperContext taskMapperContext);  }
@Test public void getDynamicTaskName() { Map<String, Object> taskInput = new HashMap<>(); taskInput.put("dynamicTaskName", "DynoTask"); String dynamicTaskName = dynamicTaskMapper.getDynamicTaskName(taskInput, "dynamicTaskName"); assertEquals("DynoTask", dynamicTaskName); }
@Test public void getDynamicTaskNameNotAvailable() { Map<String, Object> taskInput = new HashMap<>(); expectedException.expect(TerminateWorkflowException.class); expectedException.expectMessage(String.format("Cannot map a dynamic task based on the parameter and input. " + "Parameter= %s, input= %s", "dynamicTaskName", taskInput)); dynamicTaskMapper.getDynamicTaskName(taskInput, "dynamicTaskName"); }