LauncherDiscoveryRequest (String[] suiteClassNames, String[] packageNameRef, String param) { if (suiteClassNames.length == 0) { return null; } LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request(); if (suiteClassNames.length == 1 && suiteClassNames[0].charAt(0) == '@') { // all tests in the package specified try (BufferedReader reader = new BufferedReader(new FileReader(suiteClassNames[0].substring(1)))) { final String packageName = reader.readLine(); if (packageName == null) return null; String tags = reader.readLine(); String filters = reader.readLine(); String line; List<DiscoverySelector> selectors = new ArrayList<>(); while ((line = reader.readLine()) != null) { DiscoverySelector selector = createSelector(line, null); if (selector != null) { selectors.add(selector); } } if (hasBrokenSelector(selectors)) { builder.filters(createMethodFilter(new ArrayList<>(selectors))); for (int i = 0; i < selectors.size(); i++) { DiscoverySelector selector = selectors.get(i); if (selector instanceof MethodSelector) { selectors.set(i, createClassSelector(((MethodSelector)selector).getClassName())); } } } packageNameRef[0] = packageName.isEmpty() ? "<default package>" : packageName; if (selectors.isEmpty()) { builder.selectors(DiscoverySelectors.selectPackage(packageName)); } else { builder.selectors(selectors); if (!packageName.isEmpty()) { builder.filters(PackageNameFilter.includePackageNames(packageName)); } } if (filters != null && !filters.isEmpty()) { String[] classNames = filters.split("\\|\\|"); for (String className : classNames) { if (!className.contains("*")) { try { Class.forName(className, false, JUnit5TestRunnerUtil.class.getClassLoader()); } catch (ClassNotFoundException e) { System.err.println(MessageFormat.format(ResourceBundle.getBundle("messages.RuntimeBundle").getString("junit.class.not.found"), className)); } } } builder.filters(ClassNameFilter.includeClassNamePatterns(classNames)); } if (tags != null && !tags.isEmpty()) { builder.filters(TagFilter.includeTags(tags.split(" "))); } return builder.filters(ClassNameFilter.excludeClassNamePatterns("com\\.intellij\\.rt.*", "com\\.intellij\\.junit3.*")).build(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } else { DiscoverySelector selector = createSelector(suiteClassNames[0], packageNameRef); if (selector instanceof MethodSelector && !loadMethodByReflection((MethodSelector)selector)) { DiscoverySelector classSelector = createClassSelector(((MethodSelector)selector).getClassName()); DiscoverySelector methodSelector = classSelector instanceof NestedClassSelector ? DiscoverySelectors.selectMethod(((NestedClassSelector)classSelector).getNestedClassName(), ((MethodSelector)selector).getMethodName()) : selector; builder.filters(createMethodFilter(Collections.singletonList(methodSelector))); selector = classSelector; } if (selector instanceof MethodSelector && param != null) { DiscoverySelector methodSelectIteration = createMethodSelectIteration(selector, param); if (methodSelectIteration != null) { return builder.selectors(methodSelectIteration).build(); } } assert selector != null : "selector by class name is never null"; return builder.selectors(selector).build(); } return null; }