ExamplesTrait extends AbstractTrait implements ToSmithyBuilder<ExamplesTrait> { @Override public Builder toBuilder() { Builder builder = new Builder().sourceLocation(getSourceLocation()); examples.forEach(builder::addExample); return builder; } private  ExamplesTrait(Builder builder); List<Example> getExamples(); @Override Builder toBuilder(); static Builder builder(); static final ShapeId ID; }
@Test public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); ArrayNode node = Node.arrayNode( Node.objectNode() .withMember("title", Node.from("foo")), Node.objectNode() .withMember("title", Node.from("qux")) .withMember("documentation", Node.from("docs")) .withMember("input", Node.objectNode().withMember("a", Node.from("b"))) .withMember("output", Node.objectNode().withMember("c", Node.from("d")))); Optional<Trait> trait = provider.createTrait( ShapeId.from("smithy.api#examples"), ShapeId.from("ns.qux#foo"), node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(ExamplesTrait.class)); ExamplesTrait examples = (ExamplesTrait) trait.get(); assertThat(examples.toNode(), equalTo(node)); assertThat(examples.toBuilder().build(), equalTo(examples)); }