This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/master by this push:
     new 41a6c45  bz-64836 junitlauncher - Use a NumberFormat to print the time 
elapsed to match what junit task prints in its summary
41a6c45 is described below

commit 41a6c4521e34afb1ac3ac419615d585b195ae217
Author: Jaikiran Pai <jaiki...@apache.org>
AuthorDate: Sun Jan 24 18:40:13 2021 +0530

    bz-64836 junitlauncher - Use a NumberFormat to print the time elapsed to 
match what junit task prints in its summary
---
 .../ant/taskdefs/optional/junitlauncher/LauncherSupport.java | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git 
a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
 
b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
index 008db18..946ba51 100644
--- 
a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
+++ 
b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
@@ -53,6 +53,7 @@ import java.io.PrintStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -609,6 +610,14 @@ public class LauncherSupport {
             });
         }
 
+
+        private static final double ONE_SECOND = 1000.0;
+        // We use this only in the testPlanExecutionFinished method, which
+        // as per the JUnit5 platform semantics won't be called concurrently
+        // by multiple threads 
(https://github.com/junit-team/junit5/issues/2539#issuecomment-766325555).
+        // So it's safe to use this without any additional thread safety 
access controls.
+        private NumberFormat timeFormatter = NumberFormat.getInstance();
+
         @Override
         public void testPlanExecutionFinished(final TestPlan testPlan) {
             super.testPlanExecutionFinished(testPlan);
@@ -629,7 +638,8 @@ public class LauncherSupport {
                 sb.append(", Skipped: ");
                 sb.append(summary.getTestsSkippedCount());
                 sb.append(", Time elapsed: ");
-                sb.append((summary.getTimeFinished() - 
summary.getTimeStarted()) / 1000f);
+                final long elapsedMs = summary.getTimeFinished() - 
summary.getTimeStarted();
+                sb.append(timeFormatter.format(elapsedMs / ONE_SECOND));
                 sb.append(" sec");
                 this.originalSysOut.println(sb.toString());
             }

Reply via email to