Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for ExampleTrait.Example equality #2009

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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