Skip to content

Commit

Permalink
#202 Adds name of class under test to error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Aug 29, 2018
1 parent 2d1c942 commit 86d93cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ public void verify() {
private void handleError(Throwable messageContainer, Throwable trueCause) {
boolean showCauseExceptionInMessage = trueCause != null && trueCause.equals(messageContainer);
Formatter message = Formatter.of(
"%%%%\nFor more information, go to: http://www.jqno.nl/equalsverifier/errormessages",
"EqualsVerifier found a problem in class %%.\n%%%%\nFor more information, go to: http://www.jqno.nl/equalsverifier/errormessages",
type.getSimpleName(),
showCauseExceptionInMessage ? trueCause.getClass().getSimpleName() + ": " : "",
messageContainer.getMessage() == null ? "" : messageContainer.getMessage());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class OutputTest extends IntegrationTestBase {

@Test
public void messageIsValidAndExceptionHasNoCause_whenEqualsVerifierFails_givenExceptionIsGeneratedByEqualsVerifierItself() {
expectMessageIsValid();
expectMessageIsValidFor(Point.class);
expectExceptionHasNoCause();

EqualsVerifier.forClass(Point.class).verify();
}

@Test
public void messageIsValidAndExceptionHasCause_whenEqualsVerifierFails_givenOriginalExceptionHasACause() {
expectMessageIsValid();
expectMessageIsValidFor(AssertionExceptionWithCauseThrower.class);
expectMessageContains(MESSAGE);
expectMessageDoesNotContain(NullPointerException.class.getSimpleName());
expectCause(NullPointerException.class);
Expand All @@ -46,7 +46,7 @@ public void messageIsValidAndExceptionHasCause_whenEqualsVerifierFails_givenOrig

@Test
public void originalMessageIsPresentInOutput_whenEqualsVerifierFails_givenOriginalExceptionHasAMessage() {
expectMessageIsValid();
expectMessageIsValidFor(UnsupportedOperationExceptionWithMessageThrower.class);
expectMessageContains(UnsupportedOperationException.class.getSimpleName(), MESSAGE);
expectMessageDoesNotContain("null");
expectCause(UnsupportedOperationException.class, MESSAGE);
Expand All @@ -56,7 +56,7 @@ public void originalMessageIsPresentInOutput_whenEqualsVerifierFails_givenOrigin

@Test
public void messageIsValidAndDoesNotContainStringNull_whenEqualsVerifierFails_givenOriginalExceptionIsBare() {
expectMessageIsValid();
expectMessageIsValidFor(IllegalStateExceptionThrower.class);
expectMessageContains(IllegalStateException.class.getSimpleName());
expectMessageDoesNotContain("null");
expectCause(IllegalStateException.class);
Expand All @@ -66,13 +66,14 @@ public void messageIsValidAndDoesNotContainStringNull_whenEqualsVerifierFails_gi

@Test
public void noStackOverflowErrorIsThrown_whenClassIsARecursiveDatastructure() {
expectMessageIsValid();
expectMessageIsValidFor(Node.class);
expectExceptionHasNoCause();

EqualsVerifier.forClass(Node.class).verify();
}

private void expectMessageIsValid() {
private void expectMessageIsValidFor(Class<?> type) {
expectMessageContains(type.getSimpleName());
expectMessageContains(SEE_ALSO, WIKIPAGE_URL);
expectMessageDoesNotContain(BLACKLISTED_EXCEPTIONS);
}
Expand Down

0 comments on commit 86d93cf

Please sign in to comment.