diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java index 3589669e03d..0c32dc009dd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java @@ -127,7 +127,7 @@ public Map getAuthSchemes(ToShapeId service) { * *

The returned map is provided in the same order as the values in the * {@code auth} trait if an auth trait is present, otherwise the result - * is returned in an undefined order. + * returned is ordered alphabetically by absolute shape id. * *

An empty map is returned if {@code service} cannot be found in the * model or is not a service shape. @@ -167,7 +167,7 @@ public Map getEffectiveAuthSchemes(ToShapeId service) { * *

The returned map is provided in the same order as the values in the * {@code auth} trait if an auth trait is present, otherwise the result - * is returned in an undefined order. + * returned is ordered alphabetically by absolute shape id. * *

An empty map is returned if {@code service} shape cannot be found * in the model or is not a service shape. An empty map is returned if diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/ServiceIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/ServiceIndexTest.java index c36e335eb15..f11902bb09e 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/ServiceIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/ServiceIndexTest.java @@ -19,7 +19,10 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.equalTo; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -80,10 +83,11 @@ public void getsAuthSchemesOfServiceWithNoAuthTrait() { Map auth = serviceIndex.getEffectiveAuthSchemes( ShapeId.from("smithy.example#ServiceWithNoAuthTrait")); - assertThat(auth.keySet(), hasSize(3)); - assertThat(auth, hasKey(HttpBasicAuthTrait.ID)); - assertThat(auth, hasKey(HttpDigestAuthTrait.ID)); - assertThat(auth, hasKey(HttpBearerAuthTrait.ID)); + List ids = new ArrayList<>(auth.keySet()); + assertThat(ids, hasSize(3)); + assertThat(ids.get(0), equalTo(HttpBasicAuthTrait.ID)); + assertThat(ids.get(1), equalTo(HttpBearerAuthTrait.ID)); + assertThat(ids.get(2), equalTo(HttpDigestAuthTrait.ID)); } @Test @@ -104,10 +108,11 @@ public void getsAuthSchemesOfOperationWithNoAuthTraitAndServiceWithNoAuthTrait() ShapeId.from("smithy.example#ServiceWithNoAuthTrait"), ShapeId.from("smithy.example#OperationWithNoAuthTrait")); - assertThat(auth.keySet(), hasSize(3)); - assertThat(auth, hasKey(HttpBasicAuthTrait.ID)); - assertThat(auth, hasKey(HttpDigestAuthTrait.ID)); - assertThat(auth, hasKey(HttpBearerAuthTrait.ID)); + List ids = new ArrayList<>(auth.keySet()); + assertThat(ids, hasSize(3)); + assertThat(ids.get(0), equalTo(HttpBasicAuthTrait.ID)); + assertThat(ids.get(1), equalTo(HttpBearerAuthTrait.ID)); + assertThat(ids.get(2), equalTo(HttpDigestAuthTrait.ID)); } @Test @@ -117,9 +122,10 @@ public void getsAuthSchemesOfOperationWithNoAuthTraitAndServiceWithAuthTrait() { ShapeId.from("smithy.example#ServiceWithAuthTrait"), ShapeId.from("smithy.example#OperationWithNoAuthTrait")); - assertThat(auth.keySet(), hasSize(2)); - assertThat(auth, hasKey(HttpBasicAuthTrait.ID)); - assertThat(auth, hasKey(HttpDigestAuthTrait.ID)); + List ids = new ArrayList<>(auth.keySet()); + assertThat(ids, hasSize(2)); + assertThat(ids.get(0), equalTo(HttpBasicAuthTrait.ID)); + assertThat(ids.get(1), equalTo(HttpDigestAuthTrait.ID)); } @Test