2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.junit5;
18 import org.junit.gen5.engine.discovery.NameBasedSelector;
19 import org.junit.gen5.launcher.TestDiscoveryRequest;
20 import org.junit.gen5.launcher.main.TestDiscoveryRequestBuilder;
22 import java.io.BufferedReader;
23 import java.io.FileReader;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.stream.Collectors;
30 public class JUnit5TestRunnerUtil {
32 public static TestDiscoveryRequest buildRequest(String[] suiteClassNames, final String name, boolean notForked) {
33 if (suiteClassNames.length == 0) {
37 final TestDiscoveryRequestBuilder builder = TestDiscoveryRequestBuilder.request();
38 final List<String> lines = new ArrayList<>();
41 if (suiteClassNames.length == 1 && suiteClassNames[0].charAt(0) == '@') {
42 // all tests in the package specified
44 BufferedReader reader = new BufferedReader(new FileReader(suiteClassNames[0].substring(1)));
46 final String packageName = reader.readLine();
47 if (packageName == null) return null;
50 final String categoryName = reader.readLine();
53 while ((line = reader.readLine()) != null) {
56 //todo set package name
57 String suiteName = packageName.length() == 0 ? "<default package>" : packageName;
63 catch (IOException e) {
69 Collections.addAll(lines, suiteClassNames);
72 final List<String> mappedLines = lines.stream().map(line -> line.replaceFirst(",", "#")).collect(Collectors.toList());
73 return builder.select(NameBasedSelector.forNames(mappedLines)).build();