Skip to content

Commit

Permalink
fix for ExampleTrait.Example equality (#2009)
Browse files Browse the repository at this point in the history
* fix for examples equality
  • Loading branch information
lewisjkl authored Oct 26, 2023
1 parent 6d1a7cd commit c752eac
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@ public Node toNode() {
return builder.build();
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Example example = (Example) o;
return allowConstraintErrors == example.allowConstraintErrors && Objects.equals(title, example.title)
&& Objects.equals(documentation, example.documentation) && Objects.equals(input, example.input)
&& Objects.equals(output, example.output) && Objects.equals(error, example.error);
}

@Override
public int hashCode() {
return Objects.hash(title, documentation, input, output, error, allowConstraintErrors);
}

@Override
public Builder toBuilder() {
return new Builder().documentation(documentation).title(title).input(input).output(output).error(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -38,13 +39,10 @@
import software.amazon.smithy.model.knowledge.TopDownIndex;
import software.amazon.smithy.model.node.ExpectationNotMetException;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.shapes.EnumShape;
import software.amazon.smithy.model.shapes.IntegerShape;
import software.amazon.smithy.model.shapes.ListShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.StringShape;
import software.amazon.smithy.model.shapes.TimestampShape;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.node.StringNode;
import software.amazon.smithy.model.shapes.*;
import software.amazon.smithy.model.traits.ExamplesTrait;
import software.amazon.smithy.model.traits.TraitDefinition;
import software.amazon.smithy.model.traits.synthetic.OriginalShapeIdTrait;

Expand Down Expand Up @@ -79,6 +77,26 @@ public void modelEquality() {
assertThat(modelA, not(equalTo(null)));
}

@Test
public void modelEqualityExamples() {
StructureShape opInput = StructureShape.builder().id(ShapeId.fromParts("foo", "FooInput")).addMember("test", ShapeId.from("smithy.api#String")).build();
Supplier<OperationShape> op = () -> {
ExamplesTrait.Example example = ExamplesTrait.Example.builder().title("anything").input(ObjectNode.builder().withMember("test", StringNode.from("something")).build()).build();
ExamplesTrait examples = ExamplesTrait.builder().addExample(example).build();
return OperationShape.builder().id(ShapeId.fromParts("foo", "Foo")).input(opInput).addTrait(examples).build();
};

Model modelA = Model.builder()
.addShape(op.get())
.build();
Model modelB = Model.builder()
.addShape(op.get())
.build();

assertThat(modelA, equalTo(modelA));
assertThat(modelA, equalTo(modelB));
}

@Test
public void successfullyExpectsShapesOfType() {
StringShape shape = StringShape.builder().id("ns.foo#A").build();
Expand Down

0 comments on commit c752eac

Please sign in to comment.