Skip to content

Commit

Permalink
Handle unnecessary stubbings failure gracefully in test report
Browse files Browse the repository at this point in the history
  • Loading branch information
gmishkin authored and raviagarwal7 committed Jul 8, 2023
1 parent f41ad50 commit cbe9ce5
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Description> 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
Expand Down

0 comments on commit cbe9ce5

Please sign in to comment.