diff --git a/src/main/java/hudson/plugins/testng/Publisher.java b/src/main/java/hudson/plugins/testng/Publisher.java index 1c2bf11a..eef6b9de 100644 --- a/src/main/java/hudson/plugins/testng/Publisher.java +++ b/src/main/java/hudson/plugins/testng/Publisher.java @@ -216,10 +216,10 @@ public void perform(Run build, FilePath workspace, Launcher launcher, fina } String pathsPattern; - if (build instanceof AbstractBuild) { + if (build instanceof AbstractBuild abstractBuild) { // replace any variables in the user specified pattern EnvVars env = build.getEnvironment(listener); - env.overrideAll(((AbstractBuild) build).getBuildVariables()); + env.overrideAll(abstractBuild.getBuildVariables()); pathsPattern = env.expand(reportFilenamePattern); } else { pathsPattern = reportFilenamePattern; @@ -268,48 +268,45 @@ public void perform(Run build, FilePath workspace, Launcher launcher, fina } else { if (thresholdMode == 1) { // number of tests if (results.getFailCount() > failedFails) { - logger.println(String.format( - "%d tests failed, which exceeded threshold of %d. Marking build as FAILURE", - results.getFailCount(), failedFails)); + logger.println("%d tests failed, which exceeded threshold of %d. Marking build as FAILURE" + .formatted(results.getFailCount(), failedFails)); build.setResult(Result.FAILURE); } else if (results.getSkipCount() > failedSkips) { - logger.println(String.format( - "%d tests were skipped, which exceeded threshold of %d. Marking build as FAILURE", - results.getSkipCount(), failedSkips)); + logger.println("%d tests were skipped, which exceeded threshold of %d. Marking build as FAILURE" + .formatted(results.getSkipCount(), failedSkips)); build.setResult(Result.FAILURE); } else if (results.getFailCount() > unstableFails) { - logger.println(String.format( - "%d tests failed, which exceeded threshold of %d. Marking build as UNSTABLE", - results.getFailCount(), unstableFails)); + logger.println("%d tests failed, which exceeded threshold of %d. Marking build as UNSTABLE" + .formatted(results.getFailCount(), unstableFails)); build.setResult(Result.UNSTABLE); } else if (results.getSkipCount() > unstableSkips) { - logger.println(String.format( - "%d tests were skipped, which exceeded threshold of %d. Marking build as UNSTABLE", - results.getSkipCount(), unstableSkips)); + logger.println( + "%d tests were skipped, which exceeded threshold of %d. Marking build as UNSTABLE" + .formatted(results.getSkipCount(), unstableSkips)); build.setResult(Result.UNSTABLE); } } else if (thresholdMode == 2) { // percentage of tests float failedPercent = 100 * results.getFailCount() / (float) results.getTotalCount(); float skipPercent = 100 * results.getSkipCount() / (float) results.getTotalCount(); if (failedPercent > failedFails) { - logger.println(String.format( - "%f%% of tests failed, which exceeded threshold of %d%%. Marking build as FAILURE", - failedPercent, failedFails)); + logger.println( + "%f%% of tests failed, which exceeded threshold of %d%%. Marking build as FAILURE" + .formatted(failedPercent, failedFails)); build.setResult(Result.FAILURE); } else if (skipPercent > failedSkips) { - logger.println(String.format( - "%f%% of tests were skipped, which exceeded threshold of %d%%. Marking build as FAILURE", - skipPercent, failedSkips)); + logger.println( + "%f%% of tests were skipped, which exceeded threshold of %d%%. Marking build as FAILURE" + .formatted(skipPercent, failedSkips)); build.setResult(Result.FAILURE); } else if (failedPercent > unstableFails) { - logger.println(String.format( - "%f%% of tests failed, which exceeded threshold of %d%%. Marking build as UNSTABLE", - failedPercent, unstableFails)); + logger.println( + "%f%% of tests failed, which exceeded threshold of %d%%. Marking build as UNSTABLE" + .formatted(failedPercent, unstableFails)); build.setResult(Result.UNSTABLE); } else if (skipPercent > unstableSkips) { - logger.println(String.format( - "%f%% of tests were skipped, which exceeded threshold of %d%%. Marking build as UNSTABLE", - skipPercent, unstableSkips)); + logger.println( + "%f%% of tests were skipped, which exceeded threshold of %d%%. Marking build as UNSTABLE" + .formatted(skipPercent, unstableSkips)); build.setResult(Result.UNSTABLE); } } else { diff --git a/src/main/java/hudson/plugins/testng/TestNGTestResultBuildAction.java b/src/main/java/hudson/plugins/testng/TestNGTestResultBuildAction.java index e7de3f00..8841fe70 100644 --- a/src/main/java/hudson/plugins/testng/TestNGTestResultBuildAction.java +++ b/src/main/java/hudson/plugins/testng/TestNGTestResultBuildAction.java @@ -11,6 +11,7 @@ import hudson.tasks.test.AbstractTestResultAction; import java.io.IOException; import java.io.PrintStream; +import java.io.Serial; import java.io.Serializable; import java.lang.ref.Reference; import java.lang.ref.WeakReference; @@ -36,6 +37,7 @@ public class TestNGTestResultBuildAction extends AbstractTestResultAction private static final Logger LOGGER = Logger.getLogger(TestNGTestResultBuildAction.class.getName()); /** Unique identifier for this class. */ + @Serial private static final long serialVersionUID = 31415926L; /** diff --git a/src/main/java/hudson/plugins/testng/results/TestNGResult.java b/src/main/java/hudson/plugins/testng/results/TestNGResult.java index 399f0ccf..5a9d4e53 100644 --- a/src/main/java/hudson/plugins/testng/results/TestNGResult.java +++ b/src/main/java/hudson/plugins/testng/results/TestNGResult.java @@ -3,6 +3,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.model.Run; import hudson.plugins.testng.PluginImpl; +import java.io.Serial; import java.io.Serializable; import java.util.*; import org.kohsuke.stapler.export.Exported; @@ -17,7 +18,9 @@ @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "ArrayList is Serializable") public class TestNGResult extends BaseResult implements Serializable { + @Serial private static final long serialVersionUID = -3491974223665601995L; + private List testList = new ArrayList(); private List passedTests = new ArrayList(); private List failedTests = new ArrayList(); @@ -169,12 +172,12 @@ public int hashCode() { @Override public String toString() { - return String.format( - "TestNGResult {" + return ("TestNGResult {" + "totalTests=%d, " + "failedTests=%d, skippedTests=%d, failedConfigs=%d, " - + "skippedConfigs=%d}", // name, - passCount + failCount + skipCount, failCount, skipCount, failedConfigCount, skippedConfigCount); + + "skippedConfigs=%d}") + .formatted( // name, + passCount + failCount + skipCount, failCount, skipCount, failedConfigCount, skippedConfigCount); } /** Updates the calculated fields */ diff --git a/src/main/java/hudson/plugins/testng/util/FormatUtil.java b/src/main/java/hudson/plugins/testng/util/FormatUtil.java index ed55226a..5cc3ee21 100644 --- a/src/main/java/hudson/plugins/testng/util/FormatUtil.java +++ b/src/main/java/hudson/plugins/testng/util/FormatUtil.java @@ -32,7 +32,7 @@ public static String formatTime(float duration) { byte seconds = (byte) duration; duration -= seconds; int milliseconds = Math.round(duration * 1000f); - return String.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, milliseconds); + return "%02d:%02d:%02d.%03d".formatted(hours, minutes, seconds, milliseconds); } catch (Exception e) { e.printStackTrace(); return "-1";