mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
still treat methods with @Test annotation inside parameterized test as test method
This commit is contained in:
@@ -58,6 +58,7 @@ public class JUnitUtil {
|
||||
public static final String AFTER_EACH_ANNOTATION_NAME = "org.junit.jupiter.api.AfterEach";
|
||||
|
||||
public static final String PARAMETRIZED_PARAMETERS_ANNOTATION_NAME = "org.junit.runners.Parameterized.Parameters";
|
||||
public static final String PARAMETRIZED_PARAMETER_ANNOTATION_NAME = "org.junit.runners.Parameterized.Parameter";
|
||||
|
||||
public static final String AFTER_CLASS_ANNOTATION_NAME = "org.junit.AfterClass";
|
||||
public static final String BEFORE_CLASS_ANNOTATION_NAME = "org.junit.BeforeClass";
|
||||
@@ -242,19 +243,6 @@ public class JUnitUtil {
|
||||
|
||||
public static boolean isTestAnnotated(final PsiMethod method) {
|
||||
if (AnnotationUtil.isAnnotated(method, TEST_ANNOTATION, false) || JUnitRecognizer.willBeAnnotatedAfterCompilation(method)) {
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(method.getContainingClass(), Collections.singleton(RUN_WITH));
|
||||
if (annotation != null) {
|
||||
final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
|
||||
for (PsiNameValuePair attribute : attributes) {
|
||||
final PsiAnnotationMemberValue value = attribute.getValue();
|
||||
if (value instanceof PsiClassObjectAccessExpression ) {
|
||||
final PsiTypeElement typeElement = ((PsiClassObjectAccessExpression)value).getOperand();
|
||||
if (typeElement.getType().getCanonicalText().equals(PARAMETERIZED_CLASS_NAME)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -20,16 +20,14 @@
|
||||
*/
|
||||
package com.intellij.execution.junit2.inspection;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInspection.reference.EntryPoint;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.execution.junit.JUnitUtil;
|
||||
import com.intellij.openapi.util.DefaultJDOMExternalizer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.util.PsiClassUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -78,6 +76,9 @@ public class JUnitEntryPoint extends EntryPoint {
|
||||
}
|
||||
if (JUnitUtil.isTestMethodOrConfig(method)) return true;
|
||||
}
|
||||
else if (psiElement instanceof PsiField) {
|
||||
return AnnotationUtil.isAnnotated((PsiField)psiElement, JUnitUtil.PARAMETRIZED_PARAMETER_ANNOTATION_NAME, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
|
||||
public class JUnitUnusedMethodsTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.addClass("package org.junit; public @interface Test {}");
|
||||
myFixture.addClass("package org.junit.runners; public class Parameterized { public @interface Parameters {} public @interface Parameter {}}");
|
||||
myFixture.addClass("package org.junit.runner; public @interface RunWith {Class value();}");
|
||||
myFixture.enableInspections(new UnusedDeclarationInspection(true));
|
||||
}
|
||||
|
||||
public void testRecognizeTestMethodInParameterizedClass() throws Exception {
|
||||
myFixture.configureByText("A.java", "import org.junit.Test;\n" +
|
||||
"import org.junit.runner.RunWith;\n" +
|
||||
"import org.junit.runners.Parameterized;\n" +
|
||||
"import java.util.*;\n" +
|
||||
"@RunWith(Parameterized.class)\n" +
|
||||
"public class A {\n" +
|
||||
" @Parameterized.Parameters\n" +
|
||||
" public static Collection<Object[]> data() {\n" +
|
||||
" return Arrays.asList(new Object[] {\"11\"}, new Object[] {\"12\"});\n" +
|
||||
" }\n" +
|
||||
" @Parameterized.Parameter\n" +
|
||||
" public String myJUnitVersion;\n" +
|
||||
" @Test\n" +
|
||||
" public void ignoredTestMethod() throws Exception {}\n" +
|
||||
"}\n");
|
||||
myFixture.testHighlighting(true, false, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user