JsonCliOutput implements CliOutput { @Override public void printStates(RunStateDataPayload runStateDataPayload) { printJson(CliUtil.groupStates(runStateDataPayload.activeStates()).entrySet().stream() .collect(toMap(e -> e.getKey().toKey(), Entry::getValue))); }  @Override void printStates(RunStateDataPayload runStateDataPayload); @Override void printEvents(List<EventInfo> eventInfos); @Override void printBackfill(Backfill backfill, boolean ignored); @Override void printBackfillPayload(BackfillPayload backfillPayload, boolean ignored); @Override void printBackfills(List<BackfillPayload> backfills, boolean ignored); @Override void printResources(List<Resource> resources); @Override void printMessage(String message); @Override void printWorkflow(Workflow workflow, WorkflowState state); @Override void printWorkflows(List<Workflow> workflows); @Override void printError(String message);  }
@Test public void shouldPrintStatesKeyedOnWorkflowIdKey() throws IOException { final WorkflowId fooWorkflowId = WorkflowId.create("foo-component", "foo-workflow"); final WorkflowId barWorkflowId = WorkflowId.create("bar-component", "bar-workflow"); final WorkflowInstance fooWorkflowInstance = WorkflowInstance.create(fooWorkflowId, "foo-param"); final WorkflowInstance barWorkflowInstance = WorkflowInstance.create(barWorkflowId, "bar-param"); final RunStateData fooRunStateData = RunStateData.create(fooWorkflowInstance, "PREPARE", StateData.newBuilder().executionId("foo-e").build()); final RunStateData barRunStateData = RunStateData.create(barWorkflowInstance, "RUNNING", StateData.newBuilder().executionId("bar-e").build()); cliOutput.printStates(RunStateDataPayload.create(List.of(fooRunStateData, barRunStateData))); final Map<String, List<RunStateData>> expectedOutput = Map.of( fooWorkflowId.toKey(), List.of(fooRunStateData), barWorkflowId.toKey(), List.of(barRunStateData)); final Map<String, List<RunStateData>> output = OBJECT_MAPPER.readValue(outContent.toString(), new TypeReference<Map<String, List<RunStateData>>>() { }); assertThat(output, is(expectedOutput)); }