From 86d93cfa400054399b7db81288140318d53c2539 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 29 Aug 2018 08:12:40 +0200 Subject: [PATCH] #202 Adds name of class under test to error messages --- .../nl/jqno/equalsverifier/EqualsVerifierApi.java | 3 ++- .../integration/operational/OutputTest.java | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java b/src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java index 75ae645bb..9f0ccbb1b 100644 --- a/src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java +++ b/src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java @@ -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()); diff --git a/src/test/java/nl/jqno/equalsverifier/integration/operational/OutputTest.java b/src/test/java/nl/jqno/equalsverifier/integration/operational/OutputTest.java index 312e42f72..958aacf30 100644 --- a/src/test/java/nl/jqno/equalsverifier/integration/operational/OutputTest.java +++ b/src/test/java/nl/jqno/equalsverifier/integration/operational/OutputTest.java @@ -28,7 +28,7 @@ public class OutputTest extends IntegrationTestBase { @Test public void messageIsValidAndExceptionHasNoCause_whenEqualsVerifierFails_givenExceptionIsGeneratedByEqualsVerifierItself() { - expectMessageIsValid(); + expectMessageIsValidFor(Point.class); expectExceptionHasNoCause(); EqualsVerifier.forClass(Point.class).verify(); @@ -36,7 +36,7 @@ public void messageIsValidAndExceptionHasNoCause_whenEqualsVerifierFails_givenEx @Test public void messageIsValidAndExceptionHasCause_whenEqualsVerifierFails_givenOriginalExceptionHasACause() { - expectMessageIsValid(); + expectMessageIsValidFor(AssertionExceptionWithCauseThrower.class); expectMessageContains(MESSAGE); expectMessageDoesNotContain(NullPointerException.class.getSimpleName()); expectCause(NullPointerException.class); @@ -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); @@ -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); @@ -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); }