StructureShape extends NamedMembersShape implements ToSmithyBuilder<StructureShape> { public static Builder builder() { return new Builder(); } private  StructureShape(Builder builder); static Builder builder(); @Override Builder toBuilder(); @Override R accept(ShapeVisitor<R> cases); @Override Optional<StructureShape> asStructureShape();  }
@Test public void returnsAppropriateType() { StructureShape shape = StructureShape.builder().id("ns.foo#bar").build(); assertEquals(shape.getType(), ShapeType.STRUCTURE); }
@Test public void mustNotContainMembersInShapeId() { Assertions.assertThrows(SourceException.class, () -> { StructureShape.builder().id("ns.foo#bar$baz").build(); }); }
@Test public void addMemberWithTarget() { StructureShape shape = StructureShape.builder() .id("ns.foo#bar") .addMember("foo", ShapeId.from("ns.foo#bam")) .build(); assertEquals(shape.getMember("foo").get(), MemberShape.builder().id(shape.getId().withMember("foo")).target("ns.foo#bam").build()); }
@Test public void addMemberWithConsumer() { StructureShape shape = StructureShape.builder() .id("ns.foo#bar") .addMember("foo", ShapeId.from("ns.foo#bam"), builder -> builder.addTrait(new SensitiveTrait())) .build(); assertEquals(shape.getMember("foo").get(), MemberShape.builder() .id(shape.getId().withMember("foo")) .target("ns.foo#bam") .addTrait(new SensitiveTrait()) .build()); }
@Test public void returnsMembers() { StructureShape shape = StructureShape.builder() .id("ns.foo#bar") .addMember("foo", ShapeId.from("ns.foo#bam")) .addMember("baz", ShapeId.from("ns.foo#bam")) .build(); assertThat(shape.members(), hasSize(2)); assertThat(shape.members(), contains(shape.getMember("foo").get(), shape.getMember("baz").get())); assertThat(shape.getAllMembers().keySet(), contains("foo", "baz")); }
@Test public void memberOrderMattersForEqualComparison() { StructureShape a = StructureShape.builder() .id("ns.foo#bar") .addMember("foo", ShapeId.from("ns.foo#bam")) .addMember("baz", ShapeId.from("ns.foo#bam")) .build(); StructureShape b = StructureShape.builder() .id("ns.foo#bar") .addMember("baz", ShapeId.from("ns.foo#bam")) .addMember("foo", ShapeId.from("ns.foo#bam")) .build(); assertThat(a, not(equalTo(b))); }