junit 5: if decided to run with junit 5, let it discover tests
[idea/community.git] / plugins / junit5_rt / src / com / intellij / junit5 / JUnit5TestRunnerUtil.java
index a8d271f648db190be2cd6742b8c343919cd59376..fb945600ac3bbd8767b7551e5cc14e653a76c623 100644 (file)
  */
 package com.intellij.junit5;
 
-import org.junit.gen5.engine.discovery.NameBasedSelector;
-import org.junit.gen5.launcher.TestDiscoveryRequest;
-import org.junit.gen5.launcher.main.TestDiscoveryRequestBuilder;
+import com.intellij.rt.execution.junit.JUnitStarter;
+import org.junit.platform.engine.discovery.DiscoverySelectors;
+import org.junit.platform.engine.discovery.PackageSelector;
+import org.junit.platform.launcher.LauncherDiscoveryRequest;
+import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
 
 import java.io.BufferedReader;
 import java.io.FileReader;
@@ -28,13 +30,13 @@ import java.util.List;
 import java.util.stream.Collectors;
 
 public class JUnit5TestRunnerUtil {
-  
-  public static TestDiscoveryRequest buildRequest(String[] suiteClassNames, String[] packageNameRef) {
+
+  public static LauncherDiscoveryRequest buildRequest(String[] suiteClassNames, String[] packageNameRef) {
     if (suiteClassNames.length == 0) {
       return null;
     }
 
-    final TestDiscoveryRequestBuilder builder = TestDiscoveryRequestBuilder.request();
+    final LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request();
     final List<String> lines = new ArrayList<>();
 
 
@@ -54,6 +56,7 @@ public class JUnit5TestRunnerUtil {
             lines.add(line);
           }
           packageNameRef[0] = packageName.length() == 0 ? "<default package>" : packageName;
+          return builder.selectors(DiscoverySelectors.selectPackage(packageName)).build();
         }
         finally {
           reader.close();
@@ -69,7 +72,7 @@ public class JUnit5TestRunnerUtil {
     }
 
     final List<String> mappedLines = lines.stream().map(line -> line.replaceFirst(",", "#")).collect(Collectors.toList());
-    return builder.select(NameBasedSelector.forNames(mappedLines)).build();
+    return builder.selectors(DiscoverySelectors.selectNames(mappedLines)).build();
   }
 
 }