From cf5351bed2742bee0adfc326d6aba5f207985348 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 19 Apr 2017 14:48:10 +0200 Subject: [PATCH] tests: prefer suite proxy if available both test and suite and suite was started --- .../GeneralToSMTRunnerEventsConvertor.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java index 16acb5870719..3f1bfb1b0f07 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java @@ -199,8 +199,8 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso } SMTestProxy parentSuite = getCurrentSuite(); - SMTestProxy testProxy = locationUrl != null ? findChildByLocation(parentSuite, locationUrl) - : findChildByName(parentSuite, fullName); + SMTestProxy testProxy = locationUrl != null ? findChildByLocation(parentSuite, locationUrl, false) + : findChildByName(parentSuite, fullName, false); if (testProxy == null) { // creates test testProxy = new SMTestProxy(testName, false, locationUrl); @@ -240,8 +240,8 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso final String locationUrl = suiteStartedEvent.getLocationUrl(); SMTestProxy parentSuite = getCurrentSuite(); - SMTestProxy newSuite = locationUrl != null ? findChildByLocation(parentSuite, locationUrl) - : findChildByName(parentSuite, suiteName); + SMTestProxy newSuite = locationUrl != null ? findChildByLocation(parentSuite, locationUrl, true) + : findChildByName(parentSuite, suiteName, true); if (newSuite == null) { //new suite newSuite = new SMTestProxy(suiteName, true, locationUrl, parentSuite.isPreservePresentableName()); @@ -265,22 +265,32 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso }); } - private SMTestProxy findChildByName(SMTestProxy parentSuite, String fullName) { - return findChild(parentSuite, fullName, SMTestProxy::getName); + private SMTestProxy findChildByName(SMTestProxy parentSuite, String fullName, boolean preferSuite) { + return findChild(parentSuite, fullName, SMTestProxy::getName, preferSuite); } - private SMTestProxy findChildByLocation(SMTestProxy parentSuite, String fullName) { - return findChild(parentSuite, fullName, SMTestProxy::getLocationUrl); + private SMTestProxy findChildByLocation(SMTestProxy parentSuite, String fullName, boolean preferSuite) { + return findChild(parentSuite, fullName, SMTestProxy::getLocationUrl, preferSuite); } - private SMTestProxy findChild(SMTestProxy parentSuite, String fullName, final Function nameFunction) { + private SMTestProxy findChild(SMTestProxy parentSuite, + String fullName, + final Function nameFunction, + boolean preferSuite) { if (myTreeBuildBeforeStart) { + Set acceptedProxies = new HashSet<>(); final Collection children = myGetChildren ? parentSuite.getChildren() : myCurrentChildren; for (SMTestProxy proxy : children) { if (fullName.equals(nameFunction.fun(proxy)) && !proxy.isFinal()) { - return proxy; + acceptedProxies.add(proxy); } } + if (!acceptedProxies.isEmpty()) { + return acceptedProxies.stream() + .filter(proxy -> proxy.isSuite() == preferSuite) + .findFirst() + .orElse(acceptedProxies.iterator().next()); + } } return null; }