junit detection: test for constructor args
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Tue, 29 Aug 2017 14:15:27 +0000 (17:15 +0300)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Tue, 29 Aug 2017 17:29:37 +0000 (20:29 +0300)
java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritor.java [new file with mode: 0644]
java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritorMultipleConstructor.java [new file with mode: 0644]
java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritorNoConstructor.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/java/execution/ConfigurationsTest.java
plugins/junit/src/com/intellij/execution/junit/TestPackage.java

diff --git a/java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritor.java b/java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritor.java
new file mode 100644 (file)
index 0000000..7ee82ad
--- /dev/null
@@ -0,0 +1,4 @@
+package test1;
+public class TestCaseInheritor extends junit.framework.TestCase {
+   public void test1() {} 
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritorMultipleConstructor.java b/java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritorMultipleConstructor.java
new file mode 100644 (file)
index 0000000..11312a5
--- /dev/null
@@ -0,0 +1,5 @@
+package test1;
+public class TestCaseInheritorMultipleConstructor extends junit.framework.TestCase {
+   public TestCaseInheritorMultipleConstructor(String s) {}
+   public void test1() {} 
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritorNoConstructor.java b/java/java-tests/testData/junit/configurations/module6/test1/TestCaseInheritorNoConstructor.java
new file mode 100644 (file)
index 0000000..79c5dd6
--- /dev/null
@@ -0,0 +1,5 @@
+package test1;
+public class TestCaseInheritorNoConstructor extends junit.framework.TestCase {
+   private TestCaseInheritorNoConstructor() {}
+   public void test1() {} 
+}
\ No newline at end of file
index bbe4a0c8dc2ff3641183f0574ea8a5d44f8b8890..7848939f687790c08286d174dbd4a1beffde27de 100644 (file)
@@ -34,6 +34,8 @@ import com.intellij.execution.testframework.SearchForTestsTask;
 import com.intellij.execution.testframework.TestSearchScope;
 import com.intellij.execution.ui.CommonJavaParametersPanel;
 import com.intellij.openapi.Disposable;
+import com.intellij.openapi.compiler.CompilerMessage;
+import com.intellij.openapi.compiler.CompilerMessageCategory;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleManager;
 import com.intellij.openapi.options.Configurable;
@@ -226,6 +228,19 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
     CHECK.containsAll(tests, new Object[]{ancestorTest, childTest1, childTest2});
   }
 
+  public void testConstructors() throws IOException, ExecutionException {
+    addModule("module6", true);
+    PsiPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage("test1");
+    JUnitConfiguration configuration = createJUnitConfiguration(psiPackage, AllInPackageConfigurationProducer.class, new MapDataContext());
+    configuration.getPersistentData().setScope(TestSearchScope.SINGLE_MODULE);
+    configuration.setModule(getModule(3));
+    assertNotNull(configuration);
+    checkPackage(psiPackage.getQualifiedName(), configuration);
+    JavaParameters parameters = checkCanRun(configuration);
+    List<String> tests = extractAllInPackageTests(parameters, psiPackage);
+    CHECK.containsAll(tests, new Object[]{"test1.TestCaseInheritor"});
+  }
+
   public void testClasspathConfiguration() throws CantRunException {
     JavaParameters parameters = new JavaParameters();
     RunConfigurationModule module = new JavaRunConfigurationModule(myProject, false);
@@ -482,7 +497,8 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
       try {
         CompilerTester tester = new CompilerTester(project, Arrays.asList(ModuleManager.getInstance(project).getModules()));
         try {
-          tester.make();
+          List<CompilerMessage> messages = tester.make();
+          assertFalse(messages.stream().anyMatch(message -> message.getCategory() == CompilerMessageCategory.ERROR));
           task.startSearch();
         }
         finally {
index d0219562dd2e2ef53a2d0946d57e4253831754bc..4afd070ad9d96354f8e6eeee82f202763c2434f3 100644 (file)
@@ -274,7 +274,6 @@ public class TestPackage extends TestObject {
 
   private static boolean hasSingleConstructor(Class<?> aClass) {
     Constructor<?>[] constructors = aClass.getConstructors();
-    return constructors.length == 0 || 
-           constructors.length == 1 && constructors[0].getParameterTypes().length == 0;
+    return constructors.length == 1 && constructors[0].getParameterTypes().length == 0;
   }
 }