From a673eed0ff23017a4379049650539f5dd80e5700 Mon Sep 17 00:00:00 2001 From: Ryan Laseter Date: Thu, 3 Jan 2019 14:20:30 -0600 Subject: [PATCH] method for default log for throwables created. Added call in SoftAssert to allow downstream modification of SoftAssert output --- CHANGES.txt | 1 + src/main/java/org/testng/asserts/Assertion.java | 17 +++++++++++++++++ .../java/org/testng/asserts/SoftAssert.java | 7 +------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2acbb35d73..dbd814ae3a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ Current +New: Added a method in Assertion class to allow downstream TestNG consumers to override the error message (Ryan Laseter) Fixed: GITHUB-165: @AfterGroups is not executed when group member fails or is skipped (Krishnan Mahadevan) Fixed: GITHUB-118: @BeforeGroups only called if group is specified explicitly (Krishnan Mahadevan) Fixed: GITHUB-182: Inherited test methods do not get expected group behavior (Krishnan Mahadevan) diff --git a/src/main/java/org/testng/asserts/Assertion.java b/src/main/java/org/testng/asserts/Assertion.java index ae4d473813..74974030c1 100644 --- a/src/main/java/org/testng/asserts/Assertion.java +++ b/src/main/java/org/testng/asserts/Assertion.java @@ -743,4 +743,21 @@ public void doAssert() { } }); } + + /*** + * Override this method should you want to change + * the default way Throwable objects are logged. + * @param error Throwable of the Assertion + * @return default throwable formatted message for TestNG + */ + protected String getErrorDetails(Throwable error) { + StringBuilder sb = new StringBuilder(); + sb.append(error.getMessage()); + Throwable cause = error.getCause(); + while (cause != null) { + sb.append(" ").append(cause.getMessage()); + cause = cause.getCause(); + } + return sb.toString(); + } } diff --git a/src/main/java/org/testng/asserts/SoftAssert.java b/src/main/java/org/testng/asserts/SoftAssert.java index d3a93db5fe..f1f2939ac9 100644 --- a/src/main/java/org/testng/asserts/SoftAssert.java +++ b/src/main/java/org/testng/asserts/SoftAssert.java @@ -37,12 +37,7 @@ public void assertAll() { sb.append(","); } sb.append("\n\t"); - sb.append(error.getMessage()); - Throwable cause = error.getCause(); - while (cause != null) { - sb.append(" ").append(cause.getMessage()); - cause = cause.getCause(); - } + sb.append(getErrorDetails(error)); } throw new AssertionError(sb.toString()); }