-
Notifications
You must be signed in to change notification settings - Fork 76
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
Apply AssertJ best practices #1031
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,7 +241,7 @@ void succeed_whenCallingForPackageRecursivelyOnAPackageContainingFailingClasses_ | |
void succeed_whenReportingOnSeveralCorrectClasses() { | ||
List<EqualsVerifierReport> reports = EqualsVerifier.forClasses(A.class, B.class, C.class).report(); | ||
|
||
assertThat(reports.size()).isEqualTo(3); | ||
assertThat(reports).hasSize(3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now when this fails you'll get a message saying "a collection was expected with three elements, but it was a collection with x elements, containing elem1, elem2, ....". Much more helpful than expected 3 but was 5. |
||
assertSuccessful(reports.get(0), A.class); | ||
assertSuccessful(reports.get(1), B.class); | ||
assertSuccessful(reports.get(2), C.class); | ||
|
@@ -251,7 +251,7 @@ void succeed_whenReportingOnSeveralCorrectClasses() { | |
void fail_whenReportingOnOneIncorrectClass() { | ||
List<EqualsVerifierReport> reports = EqualsVerifier.forClasses(A.class, IncorrectM.class, C.class).report(); | ||
|
||
assertThat(reports.size()).isEqualTo(3); | ||
assertThat(reports).hasSize(3); | ||
assertSuccessful(reports.get(0), A.class); | ||
assertSuccessful(reports.get(2), C.class); | ||
assertUnsuccessful(reports.get(1), IncorrectM.class, "Subclass: equals is not final."); | ||
|
@@ -262,7 +262,7 @@ void fail_whenReportingOnTwoIncorrectClasses() { | |
List<EqualsVerifierReport> reports = | ||
EqualsVerifier.forClasses(A.class, IncorrectM.class, C.class, IncorrectN.class).report(); | ||
|
||
assertThat(reports.size()).isEqualTo(4); | ||
assertThat(reports).hasSize(4); | ||
assertSuccessful(reports.get(0), A.class); | ||
assertSuccessful(reports.get(2), C.class); | ||
assertUnsuccessful(reports.get(1), IncorrectM.class, "Subclass: equals is not final."); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ void allValuesReturnToOriginalState_whenEqualsVerifierIsFinishedWithException() | |
} | ||
catch (AssertionError e) { | ||
// Make sure EV fails on a check that actually mutates fields. | ||
assertThat(e.getMessage().contains("Mutability")).isTrue(); | ||
assertThat(e.getMessage()).contains("Mutability"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion failure here would go from expected true was false to expected a string containing Mutability, but was .... |
||
} | ||
catch (Throwable ignored) { | ||
fail("EqualsVerifier should have failed on FailingEqualsContainerContainer with a different exception."); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ void onlySubClassFields() { | |
@Test | ||
void noFields() { | ||
FieldIterable iterable = FieldIterable.of(NoFields.class); | ||
assertThat(iterable.iterator().hasNext()).isFalse(); | ||
assertThat(iterable.iterator()).isExhausted(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again; we're being more expressive about what we expect, such that you get better failure messages. |
||
} | ||
|
||
@Test | ||
|
@@ -113,7 +113,7 @@ void orderingTest() { | |
@Test | ||
void interfaceTest() { | ||
FieldIterable iterable = FieldIterable.of(Interface.class); | ||
assertThat(iterable.iterator().hasNext()).isFalse(); | ||
assertThat(iterable.iterator()).isExhausted(); | ||
} | ||
|
||
@Test | ||
|
@@ -129,13 +129,13 @@ void nextAfterLastElement() { | |
@Test | ||
void objectHasNoElements() { | ||
FieldIterable iterable = FieldIterable.of(Object.class); | ||
assertThat(iterable.iterator().hasNext()).isFalse(); | ||
assertThat(iterable.iterator()).isExhausted(); | ||
} | ||
|
||
@Test | ||
void ignoreSyntheticFields() { | ||
FieldIterable iterable = FieldIterable.of(Outer.Inner.class); | ||
assertThat(iterable.iterator().hasNext()).isFalse(); | ||
assertThat(iterable.iterator()).isExhausted(); | ||
} | ||
|
||
@Test | ||
|
@@ -145,7 +145,7 @@ void ignoreNonSyntheticCoberturaFields() { | |
for (FieldProbe probe : iterable) { | ||
fields.add(probe.getField()); | ||
} | ||
assertThat(fields.size()).isEqualTo(1); | ||
assertThat(fields).hasSize(1); | ||
assertThat(fields.get(0).getName()).isEqualTo("i"); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can chain assertions on the same element; I think that looks best with each on a new line, but spotless disagrees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it would look better that way. It's hard to find a good formatter configuration that works well in all situations...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing
//
to the rescue 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, that's not a bad workaround, I'll keep it in mind 😄