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

Reset ModelAssembler's validationEventListener to default #1124

Merged
merged 1 commit into from
Mar 11, 2022
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 @@ -166,7 +166,7 @@ public ModelAssembler reset() {
documentNodes.clear();
disablePrelude = false;
disableValidation = false;
validationEventListener = null;
validationEventListener = DEFAULT_EVENT_LISTENER;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,27 @@ public void transientTraitsAreNotValidated() {
assertThat(model.expectShape(stringShape.getId()).expectTrait(OriginalShapeIdTrait.class).getOriginalId(),
equalTo(originalId));
}

@Test
public void resetDoesNotBarf() {
ModelAssembler assembler = new ModelAssembler();
assembler.assemble();
assembler.reset();
assembler.assemble();
}

// reset() affects multiple properties of the ModelAssembler. The test asserts one of them (shapes).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think it was worth asserting each property, by exposing a package-private access to each property, or a separate behavior test like below. LMK if you think otherwise.

@Test
public void reset() {
ModelAssembler assembler = new ModelAssembler();

StringShape shape = StringShape.builder().id("ns.foo#Bar").build();
assembler.addShape(shape);
ValidatedResult<Model> result = assembler.assemble();
assertThat(result.unwrap().getShape(ShapeId.from("ns.foo#Bar")), is(Optional.of(shape)));

assembler.reset();
result = assembler.assemble();
assertThat(result.unwrap().getShape(ShapeId.from("ns.foo#Bar")), is(Optional.empty()));
}
}