### Question:
ChoiceMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps) { DataShape outputShape = StepMetadataHelper.getLastWithOutputShape(previousSteps) .flatMap(Step::outputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); return new DynamicActionMetadata.Builder() .inputShape(outputShape) .outputShape(step.outputDataShape() .orElse(StepMetadataHelper.ANY_SHAPE)) .build(); }  @Override boolean canHandle(StepKind kind); @Override DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps);  }### Answer:
@Test public void shouldCreateMetaDataFromSurroundingSteps() { Step previousStep = new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .inputDataShape(StepMetadataHelper.NO_SHAPE) .outputDataShape(new DataShape.Builder() .kind(DataShapeKinds.JSON_INSTANCE) .specification("{}") .description("previousOutput") .addVariant(testShape("variant1")) .addVariant(testShape("variant2")) .build()) .build()) .build()) .build(); Step subsequentStep = new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .inputDataShape(new DataShape.Builder() .kind(DataShapeKinds.JSON_INSTANCE) .specification("{}") .description("subsequentInput") .addVariant(testShape("variant3")) .addVariant(testShape("variant4")) .build()) .outputDataShape(StepMetadataHelper.NO_SHAPE) .build()) .build()) .build(); DynamicActionMetadata metadata = metadataHandler.createMetadata(choiceStep, Collections.singletonList(previousStep), Collections.singletonList(subsequentStep)); Assert.assertNotNull(metadata.outputShape()); Assert.assertEquals(DataShapeKinds.ANY, metadata.outputShape().getKind()); Assert.assertNotNull(metadata.inputShape()); Assert.assertEquals(DataShapeKinds.JSON_INSTANCE, metadata.inputShape().getKind()); Assert.assertEquals("previousOutput", metadata.inputShape().getDescription()); Assert.assertEquals(2, metadata.inputShape().getVariants().size()); Assert.assertEquals("variant1", metadata.inputShape().getVariants().get(0).getMetadata().get("name")); Assert.assertEquals("variant2", metadata.inputShape().getVariants().get(1).getMetadata().get("name")); }
@Test public void shouldCreateMetaDataFromAnyShapes() { Step previousStep = new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .inputDataShape(StepMetadataHelper.NO_SHAPE) .outputDataShape(StepMetadataHelper.ANY_SHAPE) .build()) .build()) .build(); Step subsequentStep = new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .inputDataShape(StepMetadataHelper.ANY_SHAPE) .outputDataShape(StepMetadataHelper.NO_SHAPE) .build()) .build()) .build(); DynamicActionMetadata metadata = metadataHandler.createMetadata(choiceStep, Collections.singletonList(previousStep), Collections.singletonList(subsequentStep)); Assert.assertEquals(StepMetadataHelper.ANY_SHAPE, metadata.inputShape()); Assert.assertEquals(StepMetadataHelper.ANY_SHAPE, metadata.outputShape()); }
@Test public void shouldCreateMetaDataFromEmptySurroundingSteps() { DynamicActionMetadata metadata = metadataHandler.createMetadata(choiceStep, Collections.emptyList(), Collections.emptyList()); Assert.assertEquals(StepMetadataHelper.NO_SHAPE, metadata.inputShape()); Assert.assertEquals(StepMetadataHelper.ANY_SHAPE, metadata.outputShape()); }