aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/junitrunner
diff options
context:
space:
mode:
authorGravatar Yunchi Luo <yunchi@compass.com>2016-08-23 20:56:46 +0000
committerGravatar John Cater <jcater@google.com>2016-08-23 22:59:31 +0000
commit7a45855aeaa56573e7497109f8a2de6d145e12c7 (patch)
treecd3a415cfa6f0aa64dd97de1f9d98b258dc5ed14 /src/java_tools/junitrunner
parent22585cb18c3666ab78fe6b02f44e7abf3b58ffea (diff)
Remove joda-time dependency from the java test runner
-- Change-Id: I89804f0993e0248e23ee61c527117a9592a828da Reviewed-on: https://bazel-review.googlesource.com/#/c/5550/3 MOS_MIGRATED_REVID=131092172
Diffstat (limited to 'src/java_tools/junitrunner')
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD1
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java16
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java7
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/BUILD1
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java13
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestInterval.java67
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestResult.java11
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java14
8 files changed, 94 insertions, 36 deletions
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
index baa4ee8c2a..327e31148c 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
@@ -20,7 +20,6 @@ java_library(
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/model",
"//third_party:dagger",
"//third_party:guava",
- "//third_party:joda_time",
"//third_party:junit4",
],
)
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java
index c9c40ee148..e0b94da611 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java
@@ -24,18 +24,14 @@ import com.google.testing.junit.runner.junit4.JUnit4Runner;
import com.google.testing.junit.runner.junit4.JUnit4RunnerModule;
import com.google.testing.junit.runner.model.AntXmlResultWriter;
import com.google.testing.junit.runner.model.XmlResultWriter;
-
import dagger.Component;
import dagger.Module;
import dagger.Provides;
-
-import org.joda.time.DateTime;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
-
import java.io.PrintStream;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.concurrent.TimeUnit;
-
import javax.inject.Singleton;
/**
@@ -97,9 +93,9 @@ public class BazelTestRunner {
printStackTracesIfJvmExitHangs(stderr);
- DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
- DateTime shutdownTime = new DateTime();
- String formattedShutdownTime = formatter.print(shutdownTime);
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Date shutdownTime = new Date();
+ String formattedShutdownTime = format.format(shutdownTime);
System.err.printf("-- JVM shutdown starting at %s --%n%n", formattedShutdownTime);
System.exit(exitCode);
}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java
index a9174ce1f2..8ee4ba3a64 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java
@@ -22,7 +22,6 @@ import java.util.List;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import javax.inject.Inject;
-import org.joda.time.Interval;
/**
* Writes the JUnit test nodes and their results into Ant-JUnit XML. Ant-JUnit XML is not a
@@ -146,13 +145,13 @@ public final class AntXmlResultWriter implements XmlResultWriter {
writer.writeAttribute(JUNIT_ATTR_TESTSUITE_ID, this.testSuiteId++);
}
- private static String getFormattedRunTime(@Nullable Interval runTimeInterval) {
+ private static String getFormattedRunTime(@Nullable TestInterval runTimeInterval) {
return runTimeInterval == null ? "0.0"
: String.valueOf(runTimeInterval.toDurationMillis() / 1000.0D);
}
- private static String getFormattedTimestamp(@Nullable Interval runTimeInterval) {
- return runTimeInterval == null ? "" : runTimeInterval.getStart().toString();
+ private static String getFormattedTimestamp(@Nullable TestInterval runTimeInterval) {
+ return runTimeInterval == null ? "" : runTimeInterval.startInstantToString();
}
private void writeTestCase(XmlWriter writer, TestResult result,
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/BUILD
index 18e37d1b5a..44bd378b9a 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/BUILD
@@ -8,7 +8,6 @@ java_library(
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/util",
"//third_party:guava",
- "//third_party:joda_time",
"//third_party:jsr305",
"//third_party:jsr330_inject",
"//third_party:junit4",
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java
index bfa57aeaba..74ab90b090 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java
@@ -31,7 +31,6 @@ import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.annotation.Nullable;
-import org.joda.time.Interval;
import org.junit.runner.Description;
/**
@@ -45,7 +44,7 @@ class TestCaseNode extends TestNode implements TestPropertyExporter.Callback {
private final ListMultimap<Description, Throwable> dynamicTestToFailures =
Multimaps.synchronizedListMultimap(LinkedListMultimap.<Description, Throwable>create());
- @Nullable private volatile Interval runTimeInterval = null;
+ @Nullable private volatile TestInterval runTimeInterval = null;
private volatile State state = State.INITIAL;
TestCaseNode(Description description, TestSuiteNode parent) {
@@ -138,15 +137,15 @@ class TestCaseNode extends TestNode implements TestPropertyExporter.Callback {
if (fromState == state && toState != state) {
state = toState;
- runTimeInterval = runTimeInterval == null
- ? new Interval(now, now) : runTimeInterval.withEndMillis(now);
+ runTimeInterval =
+ runTimeInterval == null ? new TestInterval(now, now) : runTimeInterval.withEndMillis(now);
return true;
}
return false;
}
@Nullable
- public Interval getRuntime() {
+ public TestInterval getRuntime() {
return runTimeInterval;
}
@@ -194,8 +193,8 @@ class TestCaseNode extends TestNode implements TestPropertyExporter.Callback {
.build();
}
- private TestResult buildDynamicResult(Description test, @Nullable Interval runTime,
- TestResult.Status status) {
+ private TestResult buildDynamicResult(
+ Description test, @Nullable TestInterval runTime, TestResult.Status status) {
// The dynamic test fails if the testcase itself fails or there is
// a dynamic failure specifically for the dynamic test.
List<Throwable> dynamicFailures = dynamicTestToFailures.get(test);
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestInterval.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestInterval.java
new file mode 100644
index 0000000000..e007a43b16
--- /dev/null
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestInterval.java
@@ -0,0 +1,67 @@
+// Copyright 2016 The Bazel Authors. All Rights Reserved.
+//
+// Licensed 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 com.google.testing.junit.runner.model;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+/**
+ * Implementation of an immutable time interval, representing a period of time between two instants.
+ *
+ * <p>This class is thread-safe and immutable.
+ */
+final class TestInterval {
+ private final long startInstant;
+ private final long endInstant;
+
+ TestInterval(long startInstant, long endInstant) {
+ if (startInstant > endInstant) {
+ throw new IllegalArgumentException("Start must be before end");
+ }
+ this.startInstant = startInstant;
+ this.endInstant = endInstant;
+ }
+
+ long getStartMillis() {
+ return startInstant;
+ }
+
+ long getEndMillis() {
+ return endInstant;
+ }
+
+ long toDurationMillis() {
+ return endInstant - startInstant;
+ }
+
+ TestInterval withEndMillis(long millis) {
+ return new TestInterval(startInstant, millis);
+ }
+
+ String startInstantToString() {
+ // Format as ISO8601 string
+ return startInstantToString(TimeZone.getDefault());
+ }
+
+ /** Exposed for testing because java Date does not allow setting of timezones. */
+ // VisibleForTesting
+ String startInstantToString(TimeZone tz) {
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
+ format.setTimeZone(tz);
+ return format.format(new Date(startInstant));
+ }
+}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestResult.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestResult.java
index 852f63aece..047b769766 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestResult.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestResult.java
@@ -17,7 +17,6 @@ package com.google.testing.junit.runner.model;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
-import org.joda.time.Interval;
/**
* Result of executing a test suite or test case.
@@ -82,8 +81,7 @@ final class TestResult {
private final String name, className;
private final Map<String, String> properties;
private final List<Throwable> failures;
- @Nullable
- private final Interval runTime;
+ @Nullable private final TestInterval runTime;
private final Status status;
private final int numTests, numFailures;
private final List<TestResult> childResults;
@@ -117,7 +115,7 @@ final class TestResult {
}
@Nullable
- Interval getRunTimeInterval() {
+ TestInterval getRunTimeInterval() {
return runTime;
}
@@ -153,8 +151,7 @@ final class TestResult {
private String className = null;
private Map<String, String> properties = null;
private List<Throwable> failures = null;
- @Nullable
- private Interval runTime = null;
+ @Nullable private TestInterval runTime = null;
private Status status = null;
private Integer numTests = null;
private Integer numFailures = null;
@@ -182,7 +179,7 @@ final class TestResult {
return this;
}
- Builder runTimeInterval(@Nullable Interval runTime) {
+ Builder runTimeInterval(@Nullable TestInterval runTime) {
if (this.runTime != null) {
throw new IllegalStateException("runTime already set");
}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java
index 437ccb149e..2ebf6ae6e1 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java
@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import org.joda.time.Interval;
import org.junit.runner.Description;
/**
@@ -88,7 +87,7 @@ class TestSuiteNode extends TestNode {
@Override
protected TestResult buildResult() {
- Interval runTime = null;
+ TestInterval runTime = null;
int numTests = 0, numFailures = 0;
LinkedList<TestResult> childResults = new LinkedList<>();
@@ -98,11 +97,14 @@ class TestSuiteNode extends TestNode {
numTests += childResult.getNumTests();
numFailures += childResult.getNumFailures();
- Interval childRunTime = childResult.getRunTimeInterval();
+ TestInterval childRunTime = childResult.getRunTimeInterval();
if (childRunTime != null) {
- runTime = runTime == null ? childRunTime
- : new Interval(Math.min(runTime.getStartMillis(), childRunTime.getStartMillis()),
- Math.max(runTime.getEndMillis(), childRunTime.getEndMillis()));
+ runTime =
+ runTime == null
+ ? childRunTime
+ : new TestInterval(
+ Math.min(runTime.getStartMillis(), childRunTime.getStartMillis()),
+ Math.max(runTime.getEndMillis(), childRunTime.getEndMillis()));
}
}