@Test public void appliesAllMappersToShapes() { ShapeId shapeId = ShapeId.from("ns.foo#id1"); StringShape shape = StringShape.builder() .id(shapeId) .addTrait(DeprecatedTrait.builder().message("foo").build()) .addTrait(new DocumentationTrait("docs", SourceLocation.NONE)) .build(); Model model = Model.builder().addShape(shape).build(); ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.mapTraits(model, Arrays.asList( (s, t) -> { if (t instanceof DeprecatedTrait) { return DeprecatedTrait.builder().sourceLocation(t.getSourceLocation()).message("baz").build(); } else { return t; } }, (s, t) -> { if (t instanceof DocumentationTrait) { return new DocumentationTrait("changed", t.getSourceLocation()); } else { return t; } } )); assertThat(result.expectShape(shapeId).getTrait(DeprecatedTrait.class), Matchers.not(Optional.empty())); assertThat(result.expectShape(shapeId).getTrait(DeprecatedTrait.class).get().getMessage().get(), Matchers.equalTo("baz")); assertThat(result.expectShape(shapeId).getTrait(DocumentationTrait.class).get().getValue(), Matchers.equalTo("changed")); }
MapTraits(BiFunction<Shape, Trait, Trait> mapper) { this.mapper = mapper; }
MapTraits { MapTraits(BiFunction<Shape, Trait, Trait> mapper) { this.mapper = mapper; } }
MapTraits { MapTraits(BiFunction<Shape, Trait, Trait> mapper) { this.mapper = mapper; } MapTraits(BiFunction<Shape, Trait, Trait> mapper); }
MapTraits { MapTraits(BiFunction<Shape, Trait, Trait> mapper) { this.mapper = mapper; } MapTraits(BiFunction<Shape, Trait, Trait> mapper);  }
MapTraits { MapTraits(BiFunction<Shape, Trait, Trait> mapper) { this.mapper = mapper; } MapTraits(BiFunction<Shape, Trait, Trait> mapper);   }