mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
testng: forbid running non-public methods for class-level annotations (IDEA-174740)
This commit is contained in:
@@ -239,8 +239,8 @@ public class TestNGUtil {
|
||||
return false;
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
//even if it has a global test, we ignore private and static methods
|
||||
if (element.hasModifierProperty(PsiModifier.PRIVATE) ||
|
||||
//even if it has a global test, we ignore non-public and static methods
|
||||
if (!element.hasModifierProperty(PsiModifier.PUBLIC) ||
|
||||
element.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+6
-13
@@ -23,22 +23,18 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.theoryinpractice.testng.TestNGFramework;
|
||||
import com.theoryinpractice.testng.model.TestData;
|
||||
import com.theoryinpractice.testng.model.TestNGTestObject;
|
||||
import com.theoryinpractice.testng.model.TestType;
|
||||
import com.theoryinpractice.testng.ui.actions.RerunFailedTestsAction;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("UndeclaredTests")
|
||||
public class DetectClassesToRunTest extends LightCodeInsightFixtureTestCase {
|
||||
@BeforeMethod
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -47,13 +43,11 @@ public class DetectClassesToRunTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.addClass("package org.testng.annotations; @interface BeforeGroups { String[] value() default {};}");
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonRelatedBeforeClassIncluded() throws Exception {
|
||||
final PsiClass configClass = myFixture.addClass("package p; public class AConfig {@org.testng.annotations.BeforeClass public void setup(){}}");
|
||||
final PsiClass testClass = myFixture.addClass("package p; public class ATest {@org.testng.annotations.Test public void testOne(){}}");
|
||||
@@ -63,7 +57,6 @@ public class DetectClassesToRunTest extends LightCodeInsightFixtureTestCase {
|
||||
doTestPackageConfiguration(configClass, testClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonRelatedIncludedWhenConfigIsLocatedInSuperclassInAnotherPackage() throws Exception {
|
||||
myFixture.addClass("package a; public class AConfig {@org.testng.annotations.BeforeClass public void setup(){}}");
|
||||
final PsiClass emptyClassWithSuperConfig = myFixture.addClass("package p; import a.AConfig; public class BConfig extends AConfig {}");
|
||||
@@ -71,7 +64,6 @@ public class DetectClassesToRunTest extends LightCodeInsightFixtureTestCase {
|
||||
doTestPackageConfiguration(emptyClassWithSuperConfig, testClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeClassIsIncludedIfRunOnlyOneMethod() throws Exception {
|
||||
final PsiClass aClass =
|
||||
myFixture.addClass("package a; public class AConfig {" +
|
||||
@@ -81,7 +73,6 @@ public class DetectClassesToRunTest extends LightCodeInsightFixtureTestCase {
|
||||
doTestMethodConfiguration(aClass, aClass.getMethods()[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneMethodWhenAnnotationIsOnBaseClassOnly() throws Exception {
|
||||
myFixture.addClass("package a; @org.testng.annotations.Test public class BaseClass {}");
|
||||
final PsiClass aClass =
|
||||
@@ -91,7 +82,11 @@ public class DetectClassesToRunTest extends LightCodeInsightFixtureTestCase {
|
||||
doTestMethodConfiguration(aClass, aClass.getMethods());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackagePrivateMethodWhenAnnotationIsOnClass() throws Exception {
|
||||
PsiClass aClass = myFixture.addClass("package a; @org.testng.annotations.Test public class MyTestClass {void testOne(){}}");
|
||||
assertFalse(new TestNGFramework().isTestMethod(aClass.getMethods()[0], false));
|
||||
}
|
||||
|
||||
public void testOneMethodWithDependencies() throws Exception {
|
||||
final PsiClass aClass =
|
||||
myFixture.addClass("package a; public class ATest {" +
|
||||
@@ -103,7 +98,6 @@ public class DetectClassesToRunTest extends LightCodeInsightFixtureTestCase {
|
||||
doTestMethodConfiguration(aClass, aClass.getMethods());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDependsOnGroupDontIncludeForeignClass() throws Exception {
|
||||
final PsiClass aClass =
|
||||
myFixture.addClass("package a; public class ATest {" +
|
||||
@@ -119,7 +113,6 @@ public class DetectClassesToRunTest extends LightCodeInsightFixtureTestCase {
|
||||
doTestClassConfiguration(aClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeGroups() throws Exception {
|
||||
final PsiClass aClass =
|
||||
myFixture.addClass("package a; public class ATest {" +
|
||||
|
||||
Reference in New Issue
Block a user