@Test
public void updatesStructureContainerWhenMemberIsRemoved() {

    ShapeId stringShapeId = ShapeId.from("ns.foo#String");
    StringShape string = StringShape.builder().id(stringShapeId).build();
    MemberShape member1 = MemberShape.builder().id("ns.foo#Structure$member1").target("ns.foo#String").build();
    MemberShape member2 = MemberShape.builder().id("ns.foo#Structure$member2").target("ns.foo#String").build();
    MemberShape member3 = MemberShape.builder().id("ns.foo#Structure$member3").target("ns.foo#String").build();
    StructureShape structure = StructureShape.builder()
            .id("ns.foo#Structure")
            .addMember(member1)
            .addMember(member2)
            .addMember(member3)
            .build();
    Model model = Model.builder()
            .addShapes(string, structure, member1, member2, member3)
            .build();
    // Remove "member2" from the structure.
    Model result = ModelTransformer.create().filterShapes(model, shape -> {
        return !shape.getId().toString().equals("ns.foo#Structure$member2");
    });
    // Ensure that the member shapes were removed from the index.
    assertThat(result.getShape(member1.getId()), Matchers.equalTo(Optional.of(member1)));
    assertThat(result.getShape(member3.getId()), Matchers.equalTo(Optional.of(member3)));
    assertThat(result.getShape(member2.getId()), Matchers.is(Optional.empty()));
    assertThat(result.getShape(structure.getId()), Matchers.not(Optional.empty()));
    // Make sure the structure was updated so that it no longer has the removed member shape.
    assertThat(result.getShape(structure.getId()).get().asStructureShape().get().getMember("member1"),
               Matchers.not(Optional.empty()));
    assertThat(result.getShape(structure.getId()).get().asStructureShape().get().getMember("member3"),
               Matchers.not(Optional.empty()));
    assertThat(result.getShape(structure.getId()).get().asStructureShape().get().getMember("member2"),
               Matchers.is(Optional.empty()));
}