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

test: improve tests for NameFilter class. #3975

Merged
merged 8 commits into from
Jun 11, 2021
7 changes: 6 additions & 1 deletion src/test/java/spoon/test/filters/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,16 @@ public void setup() throws Exception {
public void testNameFilter() throws Exception {
// contract: legacy NameFilter is tested and works
CtClass<?> foo = factory.Package().get("spoon.test.filters.testclasses").getType("Foo");
assertEquals("Foo", foo.getSimpleName());
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved
List<CtNamedElement> elements = foo.getElements(new NameFilter<>("i"));
// contract: tests NameFilter constructor for cases other than null
assertEquals(1, elements.size());
// contract: tests NameFilter constructor for null value case
Copy link
Collaborator

Choose a reason for hiding this comment

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

The contract should not say what the test does, but what is expected to happen. For example, this one ought to say contract: NameFilter constructor should throw IllegalArgumentException when passed null

The same problem exists with all of the contracts you have written here, they just say what the test does, while they should detail the expected outcome of some action.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it 👍🏼

assertThrows(IllegalArgumentException.class, () -> foo.getElements(new NameFilter<>(null)));
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved
// contract: tests the getType method of the NameFilter class
assertEquals("CtNamedElement",new NameFilter<>("i").getType().getSimpleName());
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved
// contract: tests the matches method of the NameFilter class
assertTrue(new NameFilter<>("i").matches(elements.get(0)));
assertThrows(IllegalArgumentException.class, () -> foo.getElements(new NameFilter<>(null)));
}


Expand Down