You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/05/22 11:41:47 UTC
[maven-surefire] branch improve-formatted-elapsed-time created (now 35e9c6f68)
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a change to branch improve-formatted-elapsed-time
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
at 35e9c6f68 Improve string representation of elapsed time
This branch includes the following new commits:
new 35e9c6f68 Improve string representation of elapsed time
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[maven-surefire] 01/01: Improve string representation of elapsed time
Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch improve-formatted-elapsed-time
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 35e9c6f6821e818ad50d8cb65be25de70585fb79
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Fri May 19 19:57:27 2023 +0200
Improve string representation of elapsed time
---
.../plugin/surefire/report/ReporterUtils.java | 44 ----------------------
.../plugin/surefire/report/WrappedReportEntry.java | 16 ++++++--
.../surefire/report/WrappedReportEntryTest.java | 2 +-
3 files changed, 13 insertions(+), 49 deletions(-)
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReporterUtils.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReporterUtils.java
deleted file mode 100644
index a673a18d0..000000000
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReporterUtils.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.plugin.surefire.report;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-/**
- * Utility for reporter classes.
- *
- * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
- * @since 2.19
- */
-final class ReporterUtils {
- private static final int MS_PER_SEC = 1000;
-
- private ReporterUtils() {
- throw new IllegalStateException("non instantiable constructor");
- }
-
- static String formatElapsedTime(double runTime) {
- NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
- numberFormat.setGroupingUsed(true);
- numberFormat.setMinimumFractionDigits(0);
- numberFormat.setMaximumFractionDigits(3);
- return numberFormat.format(runTime / MS_PER_SEC);
- }
-}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java
index 97b3734c2..910c819d2 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java
@@ -20,7 +20,9 @@ package org.apache.maven.plugin.surefire.report;
import javax.annotation.Nonnull;
+import java.text.MessageFormat;
import java.util.Collections;
+import java.util.Locale;
import java.util.Map;
import org.apache.maven.surefire.api.report.ReportEntry;
@@ -29,7 +31,6 @@ import org.apache.maven.surefire.api.report.StackTraceWriter;
import org.apache.maven.surefire.api.report.TestSetReportEntry;
import static java.util.Collections.unmodifiableMap;
-import static org.apache.maven.plugin.surefire.report.ReporterUtils.formatElapsedTime;
import static org.apache.maven.surefire.api.util.internal.StringUtils.NL;
import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank;
@@ -37,6 +38,8 @@ import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank;
* @author Kristian Rosenvold
*/
public class WrappedReportEntry implements TestSetReportEntry {
+ private static final float ONE_SECOND = 1000.0f;
+
private final ReportEntry original;
private final ReportEntryType reportEntryType;
@@ -49,6 +52,11 @@ public class WrappedReportEntry implements TestSetReportEntry {
private final Map<String, String> systemProperties;
+ // The idea is to always display four digits for visually consistent output
+ private final MessageFormat elapsedTimeFormat = new MessageFormat(
+ "{0,choice,0#0|0.0<{0,number,0.000}|10#{0,number,0.00}|100#{0,number,0.0}|1000#{0,number,0}} s",
+ Locale.ROOT);
+
public WrappedReportEntry(
ReportEntry original,
ReportEntryType reportEntryType,
@@ -140,7 +148,7 @@ public class WrappedReportEntry implements TestSetReportEntry {
}
public String elapsedTimeAsString() {
- return formatElapsedTime(getElapsed());
+ return getElapsed() != null ? elapsedTimeFormat.format(new Object[] {getElapsed() / ONE_SECOND}) : null;
}
String getReportSourceName() {
@@ -165,13 +173,13 @@ public class WrappedReportEntry implements TestSetReportEntry {
public String getOutput(boolean trimStackTrace) {
String outputLine =
- getElapsedTimeSummary() + " <<< " + getReportEntryType().name() + "!";
+ getElapsedTimeSummary() + " <<< " + getReportEntryType().name() + "!";
String trimmedStackTrace = getStackTrace(trimStackTrace);
return trimmedStackTrace == null ? outputLine : outputLine + NL + trimmedStackTrace;
}
public String getElapsedTimeVerbose() {
- return "Time elapsed: " + elapsedTimeAsString() + " s";
+ return "Time elapsed: " + (getElapsed() != null ? elapsedTimeAsString() : "(unknown)");
}
public String getElapsedTimeSummary() {
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java
index 0e08294a9..97e1b4cca 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java
@@ -78,7 +78,7 @@ public class WrappedReportEntryTest extends TestCase {
assertNull(wr.getStackTraceWriter());
assertEquals("surefire.testcase.JunitParamsTest.testSum Time elapsed: 0.012 s", wr.getElapsedTimeSummary());
assertEquals(
- "surefire.testcase.JunitParamsTest.testSum Time elapsed: 0.012 s <<< ERROR!", wr.getOutput(false));
+ "surefire.testcase.JunitParamsTest.testSum Time elapsed: 0.012 s <<< ERROR!", wr.getOutput(false));
assertEquals("exception", wr.getMessage());
}