MapShapes { MapShapes(Function<Shape, Shape> mapper) { this.mapper = mapper; } MapShapes(Function<Shape, Shape> mapper);   }
@Test public void replacesMappedShapes() { ShapeId shapeId = ShapeId.from("ns.foo#id1"); StringShape shape = StringShape.builder() .id(shapeId) .addTrait(new SensitiveTrait()) .build(); Model model = Model.builder().addShape(shape).build(); ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.mapShapes(model, s -> Shape.shapeToBuilder(s).removeTrait("sensitive").build()); assertThat(result.expectShape(shapeId).getId(), Matchers.equalTo(shapeId)); assertThat(result.expectShape(shapeId).getTrait(SensitiveTrait.class), Matchers.is(Optional.empty())); }
@Test public void throwsWhenMapperChangesShapeId() { Assertions.assertThrows(RuntimeException.class, () -> { ShapeId shapeId = ShapeId.from("ns.foo#id1"); StringShape shape = StringShape.builder().id(shapeId).build(); Model model = Model.builder().addShape(shape).build(); ModelTransformer transformer = ModelTransformer.create(); transformer.mapShapes(model, (s -> Shape.shapeToBuilder(s).id("ns.foo#change").build())); }); }
@Test public void mapsUsingAllMappers() { ShapeId shapeId = ShapeId.from("ns.foo#id1"); StringShape shape = StringShape.builder() .id(shapeId) .addTrait(new SensitiveTrait()) .addTrait(new DocumentationTrait("docs", SourceLocation.NONE)) .build(); Model model = Model.builder().addShape(shape).build(); ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.mapShapes(model, Arrays.asList( s -> Shape.shapeToBuilder(s).removeTrait("sensitive").build(), s -> Shape.shapeToBuilder(s).removeTrait("documentation").build())); assertThat(result.expectShape(shapeId).getTrait(SensitiveTrait.class), Matchers.is(Optional.empty())); assertThat(result.expectShape(shapeId).getTrait(DocumentationTrait.class), Matchers.is(Optional.empty())); }