From e564d1759ce845ed817899c2705ae03bb5852da2 Mon Sep 17 00:00:00 2001 From: Fredrik Andersson Date: Fri, 9 Aug 2024 15:25:45 +0200 Subject: [PATCH 1/5] [SUREFIRE-2172] StringUtils: yet more of them --- .../api/report/LegacyPojoStackTraceWriter.java | 6 ++---- .../maven/surefire/its/JUnit47RedirectOutputIT.java | 10 +++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/report/LegacyPojoStackTraceWriter.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/report/LegacyPojoStackTraceWriter.java index 21466f41b4..15aa6b8a05 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/report/LegacyPojoStackTraceWriter.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/report/LegacyPojoStackTraceWriter.java @@ -21,8 +21,6 @@ import java.io.PrintWriter; import java.io.StringWriter; -import org.apache.maven.surefire.api.util.internal.StringUtils; - import static org.apache.maven.surefire.shared.utils.StringUtils.isNotEmpty; /** @@ -54,7 +52,7 @@ public String writeTraceToString() { if (isMultiLineExceptionMessage(t)) { // SUREFIRE-986 String exc = t.getClass().getName() + ": "; - if (StringUtils.startsWith(builder, exc)) { + if (builder.toString().startsWith(exc)) { builder.insert(exc.length(), '\n'); } } @@ -105,7 +103,7 @@ public String writeTrimmedTraceToString() { String marker = "at " + testClass + "." + testMethod; - String[] lines = StringUtils.split(text, "\n"); + String[] lines = text.split("\n"); int lastLine = lines.length - 1; int causedByLine = -1; // skip first diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java index 6e7b5e30f0..3ba833cdc4 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java @@ -18,7 +18,6 @@ */ package org.apache.maven.surefire.its; -import org.apache.commons.lang3.StringUtils; import org.apache.maven.surefire.its.fixture.OutputValidator; import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.apache.maven.surefire.its.fixture.SurefireLauncher; @@ -46,11 +45,11 @@ public void testClassesParallel() { } private void checkReports(OutputValidator validator) { - String report = StringUtils.trimToNull(validator + String report = trimToNull(validator .getSurefireReportsFile("junit47ConsoleOutput.Test1-output.txt") .readFileToString()); assertNotNull(report); - String report2 = StringUtils.trimToNull(validator + String report2 = trimToNull(validator .getSurefireReportsFile("junit47ConsoleOutput.Test2-output.txt") .readFileToString()); assertNotNull(report2); @@ -59,6 +58,11 @@ private void checkReports(OutputValidator validator) { .exists()); } + private String trimToNull(String string) { + String str = string.trim(); + return str.isEmpty() ? null : str; + } + private SurefireLauncher unpack() { return unpack("/junit47-redirect-output"); } From c337dfe2393d7dc23f0eef843507267e0999187a Mon Sep 17 00:00:00 2001 From: Fredrik Andersson Date: Thu, 22 Aug 2024 22:12:54 +0200 Subject: [PATCH 2/5] Fix code after feedback --- .../surefire/its/JUnit47RedirectOutputIT.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java index 3ba833cdc4..fb7961c717 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java @@ -23,8 +23,7 @@ import org.apache.maven.surefire.its.fixture.SurefireLauncher; import org.junit.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; /** * @@ -45,24 +44,19 @@ public void testClassesParallel() { } private void checkReports(OutputValidator validator) { - String report = trimToNull(validator + String report = validator .getSurefireReportsFile("junit47ConsoleOutput.Test1-output.txt") - .readFileToString()); - assertNotNull(report); - String report2 = trimToNull(validator + .readFileToString(); + assertTrue(report.isEmpty()); + String report2 = validator .getSurefireReportsFile("junit47ConsoleOutput.Test2-output.txt") - .readFileToString()); - assertNotNull(report2); + .readFileToString(); + assertTrue(report2.isEmpty()); assertFalse(validator .getSurefireReportsFile("junit47ConsoleOutput.Test3-output.txt") .exists()); } - private String trimToNull(String string) { - String str = string.trim(); - return str.isEmpty() ? null : str; - } - private SurefireLauncher unpack() { return unpack("/junit47-redirect-output"); } From 94ee5698c945843ebb2a376a2dd3db24800837c3 Mon Sep 17 00:00:00 2001 From: Fredrik Andersson Date: Mon, 26 Aug 2024 19:39:47 +0200 Subject: [PATCH 3/5] Minor import adjustment --- .../org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java index fb7961c717..15d3400e78 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnit47RedirectOutputIT.java @@ -23,7 +23,8 @@ import org.apache.maven.surefire.its.fixture.SurefireLauncher; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * From 11bbb7972ab1d4ae13dd08cfd98872d52555b235 Mon Sep 17 00:00:00 2001 From: Fredrik Andersson Date: Mon, 28 Oct 2024 21:19:54 +0100 Subject: [PATCH 4/5] Empty commit, to trigger build From 56e87b9138a659bf131afff11ecf156b40043b83 Mon Sep 17 00:00:00 2001 From: Fredrik Andersson Date: Mon, 28 Oct 2024 21:40:05 +0100 Subject: [PATCH 5/5] Change after comment --- .../maven/surefire/api/report/LegacyPojoStackTraceWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/report/LegacyPojoStackTraceWriter.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/report/LegacyPojoStackTraceWriter.java index 15aa6b8a05..5f01ee56c7 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/report/LegacyPojoStackTraceWriter.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/report/LegacyPojoStackTraceWriter.java @@ -52,7 +52,7 @@ public String writeTraceToString() { if (isMultiLineExceptionMessage(t)) { // SUREFIRE-986 String exc = t.getClass().getName() + ": "; - if (builder.toString().startsWith(exc)) { + if (builder.indexOf(exc) == 0) { builder.insert(exc.length(), '\n'); } }