Skip to content

Commit

Permalink
Add test for mixin redefined member ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Mar 17, 2022
1 parent 7cad68a commit 56ab912
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,41 @@ public void flatteningStructureWithNoMixinsDoesNothing() {

assertThat(shape, equalTo(StructureShape.builder().id("smithy.example#A").build()));
}

@Test
public void redefiningMembersPreservesOrder() {
StringShape string = StringShape.builder().id("smithy.example#String").build();
StructureShape mixin1 = StructureShape.builder()
.id("smithy.example#Mixin1")
.addTrait(MixinTrait.builder().build())
.addMember("a", string.getId())
.addMember("b", string.getId())
.addMember("c", string.getId())
.build();
StructureShape mixin2 = StructureShape.builder()
.id("smithy.example#Mixin2")
.addTrait(MixinTrait.builder().build())
.addMember("c", string.getId())
.addMember("b", string.getId())
.addMember("a", string.getId())
.build();
StructureShape mixin3 = StructureShape.builder()
.id("smithy.example#Mixin3")
.addTrait(MixinTrait.builder().build())
.addMember("b", string.getId())
.addMember("c", string.getId())
.addMember("a", string.getId())
.addMixin(mixin2)
.build();
StructureShape concrete = StructureShape.builder()
.id("smithy.example#Concrete")
// Note that d is added before mixins, but the builder tracks this
// and handles ordering appropriately when building the shape.
.addMember("d", string.getId())
.addMixin(mixin1)
.addMixin(mixin3)
.build();

assertThat(concrete.getMemberNames(), contains("a", "b", "c", "d"));
}
}

0 comments on commit 56ab912

Please sign in to comment.