2 * Copyright 2000-2014 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.execution.junit;
18 import com.intellij.execution.CantRunException;
19 import com.intellij.execution.configurations.JavaRunConfigurationModule;
20 import com.intellij.execution.configurations.RuntimeConfigurationError;
21 import com.intellij.execution.configurations.RuntimeConfigurationException;
22 import com.intellij.execution.runners.ExecutionEnvironment;
23 import com.intellij.execution.util.JavaParametersUtil;
24 import com.intellij.execution.util.ProgramParametersUtil;
25 import com.intellij.psi.*;
26 import com.intellij.refactoring.listeners.RefactoringElementListener;
32 class TestCategory extends TestPackage {
33 public TestCategory(JUnitConfiguration configuration, ExecutionEnvironment environment) {
34 super(configuration, environment);
38 public void checkConfiguration() throws RuntimeConfigurationException {
39 JavaParametersUtil.checkAlternativeJRE(getConfiguration());
40 ProgramParametersUtil.checkWorkingDirectoryExist(
41 getConfiguration(), getConfiguration().getProject(), getConfiguration().getConfigurationModule().getModule());
42 final String category = getConfiguration().getPersistentData().getCategory();
43 if (category == null || category.isEmpty()) {
44 throw new RuntimeConfigurationError("Category is not specified");
46 final JavaRunConfigurationModule configurationModule = getConfiguration().getConfigurationModule();
47 if (getSourceScope() == null) {
48 configurationModule.checkForWarning();
50 configurationModule.findNotNullClass(category);
54 protected PsiPackage getPackage(JUnitConfiguration.Data data) throws CantRunException {
55 return JavaPsiFacade.getInstance(getConfiguration().getProject()).findPackage("");
59 public String suggestActionName() {
60 return "Tests of " + getConfiguration().getPersistentData().getCategory();
64 public boolean isConfiguredByElement(JUnitConfiguration configuration,
67 PsiPackage testPackage,
68 PsiDirectory testDir) {
73 public RefactoringElementListener getListener(final PsiElement element, final JUnitConfiguration configuration) {
74 return RefactoringListeners.getClassOrPackageListener(element, configuration.myCategory);