junit category support (IDEA-88389)

This commit is contained in:
Anna Kozlova
2014-04-24 16:14:24 +02:00
parent 3f304a3a15
commit bcc4a00bbd
10 changed files with 296 additions and 26 deletions
@@ -51,6 +51,7 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
@NonNls public static final String TEST_CLASS = "class";
@NonNls public static final String TEST_PACKAGE = "package";
@NonNls public static final String TEST_DIRECTORY = "directory";
@NonNls public static final String TEST_CATEGORY = "category";
@NonNls public static final String TEST_METHOD = "method";
@NonNls private static final String PATTERN_EL_NAME = "pattern";
@NonNls public static final String TEST_PATTERN = PATTERN_EL_NAME;
@@ -295,6 +296,12 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
final String dirName = dirNameElement.getAttributeValue("value");
getPersistentData().setDirName(FileUtil.toSystemDependentName(dirName));
}
final Element categoryNameElement = element.getChild("category");
if (categoryNameElement != null) {
final String categoryName = categoryNameElement.getAttributeValue("value");
getPersistentData().setCategoryName(categoryName);
}
}
public void writeExternal(final Element element) throws WriteExternalException {
@@ -311,6 +318,14 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
dirNameElement.setAttribute("value", FileUtil.toSystemIndependentName(dirName));
element.addContent(dirNameElement);
}
final String categoryName = persistentData.getCategory();
if (!categoryName.isEmpty()) {
final Element categoryNameElement = new Element("category");
categoryNameElement.setAttribute("value", categoryName);
element.addContent(categoryNameElement);
}
final Element patternsElement = new Element(PATTERNS_EL_NAME);
for (String o : persistentData.getPatterns()) {
final Element patternElement = new Element(PATTERN_EL_NAME);
@@ -379,6 +394,7 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
public static class Data implements Cloneable {
public String PACKAGE_NAME;
private String DIR_NAME;
private String CATEGORY_NAME;
public String MAIN_CLASS_NAME;
public String METHOD_NAME;
public String TEST_OBJECT = TEST_CLASS;
@@ -386,13 +402,13 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
public String PARAMETERS;
public String WORKING_DIRECTORY;
private String FORK_MODE = "none";
private Set<String> myPattern = new LinkedHashSet<String>();
private Set<String> myPattern = new LinkedHashSet<String>();
//iws/ipr compatibility
public String ENV_VARIABLES;
private Map<String, String> myEnvs = new LinkedHashMap<String, String>();
public boolean PASS_PARENT_ENVS = true;
public boolean PASS_PARENT_ENVS = true;
public TestSearchScope.Wrapper TEST_SEARCH_SCOPE = new TestSearchScope.Wrapper();
public boolean equals(final Object object) {
@@ -407,7 +423,8 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
Comparing.equal(PARAMETERS, second.PARAMETERS) &&
Comparing.equal(myPattern, second.myPattern) &&
Comparing.equal(FORK_MODE, second.FORK_MODE) &&
Comparing.equal(DIR_NAME, second.DIR_NAME);
Comparing.equal(DIR_NAME, second.DIR_NAME) &&
Comparing.equal(CATEGORY_NAME, second.CATEGORY_NAME);
}
public int hashCode() {
@@ -420,7 +437,8 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
Comparing.hashcode(PARAMETERS) ^
Comparing.hashcode(myPattern) ^
Comparing.hashcode(FORK_MODE) ^
Comparing.hashcode(DIR_NAME);
Comparing.hashcode(DIR_NAME) ^
Comparing.hashcode(CATEGORY_NAME);
}
public TestSearchScope getScope() {
@@ -559,6 +577,14 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
public void setDirName(String dirName) {
DIR_NAME = dirName;
}
public String getCategory() {
return CATEGORY_NAME != null ? CATEGORY_NAME : "";
}
public void setCategoryName(String categoryName) {
CATEGORY_NAME = categoryName;
}
}
}
@@ -0,0 +1,70 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit;
import com.intellij.execution.CantRunException;
import com.intellij.execution.configurations.JavaRunConfigurationModule;
import com.intellij.execution.configurations.RuntimeConfigurationError;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.util.JavaParametersUtil;
import com.intellij.execution.util.ProgramParametersUtil;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
/**
* User: anna
* Date: 4/21/11
*/
class TestCategory extends TestPackage {
private final Project myProject;
public TestCategory(Project project,
JUnitConfiguration configuration,
ExecutionEnvironment environment) {
super(project, configuration, environment);
myProject = project;
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
JavaParametersUtil.checkAlternativeJRE(myConfiguration);
ProgramParametersUtil.checkWorkingDirectoryExist(myConfiguration, myConfiguration.getProject(), myConfiguration.getConfigurationModule().getModule());
final String category = myConfiguration.getPersistentData().getCategory();
if (category == null || category.isEmpty()) {
throw new RuntimeConfigurationError("Category is not specified");
}
final JavaRunConfigurationModule configurationModule = myConfiguration.getConfigurationModule();
if (getSourceScope() == null) {
configurationModule.checkForWarning();
}
configurationModule.findNotNullClass(category);
}
@Override
protected PsiPackage getPackage(JUnitConfiguration.Data data) throws CantRunException {
return JavaPsiFacade.getInstance(myProject).findPackage("");
}
@Override
public boolean isConfiguredByElement(JUnitConfiguration configuration,
PsiClass testClass,
PsiMethod testMethod,
PsiPackage testPackage,
PsiDirectory testDir) {
return false;
}
}
@@ -98,15 +98,21 @@ public abstract class TestObject implements JavaCommandLine {
final Project project,
final JUnitConfiguration configuration,
ExecutionEnvironment environment) {
if (JUnitConfiguration.TEST_METHOD.equals(id))
if (JUnitConfiguration.TEST_METHOD.equals(id)) {
return new TestMethod(project, configuration, environment);
if (JUnitConfiguration.TEST_CLASS.equals(id))
}
if (JUnitConfiguration.TEST_CLASS.equals(id)) {
return new TestClass(project, configuration, environment);
if (JUnitConfiguration.TEST_PACKAGE.equals(id))
}
if (JUnitConfiguration.TEST_PACKAGE.equals(id)){
return new TestPackage(project, configuration, environment);
else if (JUnitConfiguration.TEST_DIRECTORY.equals(id)) {
}
if (JUnitConfiguration.TEST_DIRECTORY.equals(id)) {
return new TestDirectory(project, configuration, environment);
}
if (JUnitConfiguration.TEST_CATEGORY.equals(id)) {
return new TestCategory(project, configuration, environment);
}
if (JUnitConfiguration.TEST_PATTERN.equals(id)) {
return new TestsPattern(project, configuration, environment);
}
@@ -486,6 +492,9 @@ public abstract class TestObject implements JavaCommandLine {
final PrintWriter writer = new PrintWriter(myTempFile, CharsetToolkit.UTF8);
try {
writer.println(packageName);
final JUnitConfiguration.Data data = myConfiguration.getPersistentData();
final String category = data.TEST_OBJECT == JUnitConfiguration.TEST_CATEGORY ? data.getCategory() : "";
writer.println(category);
final List<String> testNames = new ArrayList<String>();
for (final T element : elements) {
final String name = nameFunction.fun(element);
@@ -3,7 +3,7 @@
<grid id="ece1c" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="28" y="28" width="722" height="509"/>
<xy x="28" y="28" width="722" height="528"/>
</constraints>
<properties/>
<border type="none"/>
@@ -123,7 +123,7 @@
</constraints>
<properties/>
</component>
<grid id="5947e" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="5947e" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
@@ -133,7 +133,7 @@
<children>
<component id="b109" class="com.intellij.openapi.ui.LabeledComponent" binding="myMethod" custom-create="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
@@ -182,10 +182,19 @@
<text resource-bundle="messages/ExecutionBundle" key="junit.configuration.class.label"/>
</properties>
</component>
<component id="ac0a6" class="com.intellij.openapi.ui.LabeledComponent" binding="myDir">
<component id="1e1f8" class="com.intellij.openapi.ui.LabeledComponent" binding="myCategory" custom-create="true">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelLocation value="West"/>
<text value="Category"/>
</properties>
</component>
<component id="ac0a6" class="com.intellij.openapi.ui.LabeledComponent" binding="myDir">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<labelLocation value="West"/>
@@ -195,7 +204,7 @@
<grid id="c9a5f" binding="myScopesPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -46,6 +46,7 @@ import com.intellij.openapi.ui.ex.MessagesEx;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.*;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.IconUtil;
@@ -72,7 +73,8 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
new TIntArrayList(new int[]{1}),
new TIntArrayList(new int[]{1, 2}),
new TIntArrayList(new int[]{3}),
new TIntArrayList(new int[]{4})
new TIntArrayList(new int[]{4}),
new TIntArrayList(new int[]{5})
);
private JComponent myPackagePanel;
@@ -81,6 +83,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
private LabeledComponent<JPanel> myPattern;
private LabeledComponent<EditorTextFieldWithBrowseButton> myClass;
private LabeledComponent<EditorTextFieldWithBrowseButton> myMethod;
private LabeledComponent<EditorTextFieldWithBrowseButton> myCategory;
// Fields
private JPanel myWholePanel;
@@ -92,7 +95,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
private TextFieldWithBrowseButton myPatternTextField;
private final ConfigurationModuleSelector myModuleSelector;
private final LabeledComponent[] myTestLocations = new LabeledComponent[5];
private final LabeledComponent[] myTestLocations = new LabeledComponent[6];
private final JUnitConfigurationModel myModel;
private final BrowseModuleValueActionListener[] myBrowsers;
@@ -135,7 +138,8 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
}
return null;
}
}
},
new CategoryBrowser(project)
};
// Garbage support
final DefaultComboBoxModel aModel = new DefaultComboBoxModel();
@@ -144,6 +148,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
aModel.addElement(JUnitConfigurationModel.PATTERN);
aModel.addElement(JUnitConfigurationModel.CLASS);
aModel.addElement(JUnitConfigurationModel.METHOD);
aModel.addElement(JUnitConfigurationModel.CATEGORY);
myTypeChooser.setModel(aModel);
myTypeChooser.setRenderer(new ListCellRendererWrapper<Integer>() {
@Override
@@ -164,6 +169,9 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
case JUnitConfigurationModel.METHOD:
setText("Method");
break;
case JUnitConfigurationModel.CATEGORY:
setText("Category");
break;
}
}
});
@@ -172,6 +180,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
myTestLocations[JUnitConfigurationModel.CLASS] = myClass;
myTestLocations[JUnitConfigurationModel.METHOD] = myMethod;
myTestLocations[JUnitConfigurationModel.DIR] = myDir;
myTestLocations[JUnitConfigurationModel.CATEGORY] = myCategory;
final JPanel panel = myPattern.getComponent();
panel.setLayout(new BorderLayout());
@@ -271,6 +280,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
myScopesPanel.setVisible(true);
myPattern.setVisible(false);
myClass.setVisible(false);
myCategory.setVisible(false);
myMethod.setVisible(false);
myDir.setVisible(false);
myForkCb.setEnabled(true);
@@ -282,6 +292,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
myDir.setVisible(true);
myPattern.setVisible(false);
myClass.setVisible(false);
myCategory.setVisible(false);
myMethod.setVisible(false);
myForkCb.setEnabled(true);
myForkCb.setModel(new DefaultComboBoxModel(FORK_MODE_ALL));
@@ -293,6 +304,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
myPattern.setVisible(false);
myDir.setVisible(false);
myClass.setVisible(true);
myCategory.setVisible(false);
myMethod.setVisible(false);
myForkCb.setEnabled(true);
myForkCb.setModel(new DefaultComboBoxModel(FORK_MODE));
@@ -304,15 +316,29 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
myPattern.setVisible(false);
myDir.setVisible(false);
myClass.setVisible(true);
myCategory.setVisible(false);
myMethod.setVisible(true);
myForkCb.setEnabled(false);
myForkCb.setSelectedItem(NONE);
} else {
} else if (selectedType == JUnitConfigurationModel.CATEGORY) {
myPackagePanel.setVisible(false);
myScopesPanel.setVisible(true);
myDir.setVisible(false);
myPattern.setVisible(false);
myClass.setVisible(false);
myCategory.setVisible(true);
myMethod.setVisible(false);
myForkCb.setEnabled(true);
myForkCb.setModel(new DefaultComboBoxModel(FORK_MODE_ALL));
myForkCb.setSelectedItem(selectedItem);
}
else {
myPackagePanel.setVisible(false);
myScopesPanel.setVisible(true);
myPattern.setVisible(true);
myDir.setVisible(false);
myClass.setVisible(false);
myCategory.setVisible(false);
myMethod.setVisible(true);
myForkCb.setEnabled(true);
myForkCb.setModel(new DefaultComboBoxModel(FORK_MODE_ALL));
@@ -379,6 +405,17 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
}
}));
myCategory = new LabeledComponent<EditorTextFieldWithBrowseButton>();
myCategory.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, new JavaCodeFragment.VisibilityChecker() {
@Override
public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
if (declaration instanceof PsiClass) {
return Visibility.VISIBLE;
}
return Visibility.NOT_VISIBLE;
}
}));
myMethod = new LabeledComponent<EditorTextFieldWithBrowseButton>();
final EditorTextFieldWithBrowseButton textFieldWithBrowseButton = new EditorTextFieldWithBrowseButton(myProject, true,
JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE,
@@ -418,6 +455,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
myMethod.setAnchor(anchor);
myPattern.setAnchor(anchor);
myPackage.setAnchor(anchor);
myCategory.setAnchor(anchor);
}
private static void addRadioButtonsListeners(final JRadioButton[] radioButtons, ChangeListener listener) {
@@ -579,4 +617,40 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> implem
myCommonJavaParameters.applyTo(currentState);
getModuleSelector().applyTo(currentState);
}
private class CategoryBrowser extends ClassBrowser {
public CategoryBrowser(Project project) {
super(project, "Category Interface");
}
protected PsiClass findClass(final String className) {
return myModuleSelector.findClass(className);
}
protected ClassFilter.ClassFilterWithScope getFilter() throws NoFilterException {
final Module module = myModuleSelector.getModule();
final GlobalSearchScope scope;
if (module == null) {
scope = GlobalSearchScope.allScope(myProject);
}
else {
scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
}
return new ClassFilter.ClassFilterWithScope() {
public GlobalSearchScope getScope() {
return scope;
}
public boolean isAccepted(final PsiClass aClass) {
return true;
}
};
}
@Override
protected void onClassChoosen(PsiClass psiClass) {
((LabeledComponent<EditorTextFieldWithBrowseButton>)getTestLocation(JUnitConfigurationModel.CATEGORY)).getComponent()
.setText(psiClass.getQualifiedName());
}
}
}
@@ -42,19 +42,23 @@ public class JUnitConfigurationModel {
public static final int METHOD = 2;
public static final int PATTERN = 3;
public static final int DIR = 4;
public static final int CATEGORY = 5;
private static final List<String> ourTestObjects;
static {
ourTestObjects = Arrays.asList(JUnitConfiguration.TEST_PACKAGE, JUnitConfiguration.TEST_CLASS, JUnitConfiguration.TEST_METHOD,
ourTestObjects = Arrays.asList(JUnitConfiguration.TEST_PACKAGE,
JUnitConfiguration.TEST_CLASS,
JUnitConfiguration.TEST_METHOD,
JUnitConfiguration.TEST_PATTERN,
JUnitConfiguration.TEST_DIRECTORY);
JUnitConfiguration.TEST_DIRECTORY,
JUnitConfiguration.TEST_CATEGORY);
}
private JUnitConfigurable myListener;
private int myType = -1;
private final Object[] myJUnitDocuments = new Object[5];
private final Object[] myJUnitDocuments = new Object[6];
private final Project myProject;
public JUnitConfigurationModel(final Project project) {
@@ -99,7 +103,8 @@ public class JUnitConfigurationModel {
data.TEST_OBJECT = testObject;
if (testObject != JUnitConfiguration.TEST_PACKAGE &&
testObject != JUnitConfiguration.TEST_PATTERN &&
testObject != JUnitConfiguration.TEST_DIRECTORY) {
testObject != JUnitConfiguration.TEST_DIRECTORY &&
testObject != JUnitConfiguration.TEST_CATEGORY) {
try {
data.METHOD_NAME = getJUnitTextValue(METHOD);
final PsiClass testClass = !myProject.isDefault() && !StringUtil.isEmptyOrSpaces(className) ? JUnitUtil.findPsiClass(className, module, myProject) : null;
@@ -124,6 +129,9 @@ public class JUnitConfigurationModel {
else if (testObject == JUnitConfiguration.TEST_DIRECTORY) {
data.setDirName(getJUnitTextValue(DIR));
}
else if (testObject == JUnitConfiguration.TEST_CATEGORY) {
data.setCategoryName(getJUnitTextValue(CATEGORY));
}
else {
final LinkedHashSet<String> set = new LinkedHashSet<String>();
final String[] patterns = getJUnitTextValue(PATTERN).split("\\|\\|");
@@ -168,6 +176,7 @@ public class JUnitConfigurationModel {
setJUnitTextValue(METHOD, data.getMethodName());
setJUnitTextValue(PATTERN, data.getPatternPresentation());
setJUnitTextValue(DIR, data.getDirName());
setJUnitTextValue(CATEGORY, data.getCategory());
}
private void setJUnitTextValue(final int index, final String text) {
@@ -52,6 +52,9 @@ public class TestRunnerUtil {
Vector vector;
try {
suiteName = reader.readLine();
reader.readLine(); //category
vector = new Vector();
String line;
while ((line = reader.readLine()) != null) {
@@ -0,0 +1,46 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.junit4;
import org.junit.experimental.categories.Categories;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
import java.util.List;
public class IdeaSuite48 extends IdeaSuite {
public IdeaSuite48(List runners, String name, Class category) throws InitializationError {
super(runners, name);
filterByCategory(category);
}
public IdeaSuite48(RunnerBuilder builder, Class[] classes, String name, Class category) throws InitializationError {
super(builder, classes, name);
filterByCategory(category);
}
private void filterByCategory(Class category) throws InitializationError {
if (category != null) {
try {
final Categories.CategoryFilter categoryFilter = new Categories.CategoryFilter(category, null);
filter(categoryFilter);
} catch (NoTestsRemainException e) {
throw new RuntimeException(e);
}
}
}
}
@@ -32,15 +32,36 @@ import java.util.*;
public class JUnit46ClassesRequestBuilder {
private JUnit46ClassesRequestBuilder() {}
public static Request getClassesRequest(final String suiteName, Class[] classes, Map classMethods) {
public static Request getClassesRequest(final String suiteName, Class[] classes, Map classMethods, Class category) {
boolean canUseSuiteMethod = canUseSuiteMethod(classMethods);
try {
final Runner suite;
if (category != null) {
try {
Class.forName("org.junit.experimental.categories.Categories");
}
catch (ClassNotFoundException e) {
throw new RuntimeException("Categories are not available");
}
}
Runner suite;
if (canUseSuiteMethod) {
suite = new IdeaSuite(collectWrappedRunners(classes), suiteName);
try {
Class.forName("org.junit.experimental.categories.Categories");
suite = new IdeaSuite48(collectWrappedRunners(classes), suiteName, category);
}
catch (ClassNotFoundException e) {
suite = new IdeaSuite(collectWrappedRunners(classes), suiteName);
}
} else {
final AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder(canUseSuiteMethod);
suite = new IdeaSuite(builder, classes, suiteName);
try {
Class.forName("org.junit.experimental.categories.Categories");
suite = new IdeaSuite48(builder, classes, suiteName, category);
}
catch (ClassNotFoundException e) {
suite = new IdeaSuite(builder, classes, suiteName);
}
}
return Request.runner(suite);
}
@@ -59,6 +59,9 @@ public class JUnit4TestRunnerUtil {
try {
final String packageName = reader.readLine();
if (packageName == null) return null;
final String categoryName = reader.readLine();
final Class category = categoryName != null && categoryName.length() > 0 ? loadTestClass(categoryName) : null;
String line;
while ((line = reader.readLine()) != null) {
@@ -85,7 +88,7 @@ public class JUnit4TestRunnerUtil {
Request allClasses;
try {
Class.forName("org.junit.runner.Computer");
allClasses = JUnit46ClassesRequestBuilder.getClassesRequest(suiteName, classes, classMethods);
allClasses = JUnit46ClassesRequestBuilder.getClassesRequest(suiteName, classes, classMethods, category);
}
catch (ClassNotFoundException e) {
allClasses = getClassRequestsUsing44API(suiteName, classes);