From 0e64397185093c23bc9ba8b9e96ae73b6b6c2eed Mon Sep 17 00:00:00 2001 From: Geoff Mishkin Date: Tue, 28 Feb 2023 16:39:50 -0500 Subject: [PATCH] Handle unnecessary stubbings failure gracefully in test report Issue: https://github.com/bazelbuild/bazel/issues/16251 PR: https://github.com/bazelbuild/bazel/pull/15023 --- .../junit/runner/model/TestSuiteModel.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteModel.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteModel.java index 3a9086721a2d98..a68494ab2cb1f4 100644 --- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteModel.java +++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteModel.java @@ -30,6 +30,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nullable; @@ -91,7 +92,27 @@ private TestCaseNode getTestCase(Description description) { private TestNode getTest(Description description) { // The description shouldn't be null, but in the test runner code we avoid throwing exceptions. - return description == null ? null : testsMap.get(description); + if (description == null) { + return null; + } + + TestNode test = testsMap.get(description); + if (test != null) { + return test; + } + + final Optional matchingSuite = testsMap.keySet().stream() + .filter(d -> d != null && d.getTestClass() != null && d.isSuite() && d.getTestClass().equals(description.getTestClass())) + .findAny(); + if (matchingSuite.isPresent()) { + final TestSuiteNode suite = (TestSuiteNode)testsMap.get(matchingSuite.get()); + test = new TestCaseNode(description, suite); + suite.addTestCase((TestCaseNode)test); + testsMap.put(description, test); + return test; + } + + return null; } // VisibleForTesting