junit4: hide class node when show method results
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 25 Jan 2012 12:12:27 +0000 (16:12 +0400)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 25 Jan 2012 12:52:27 +0000 (16:52 +0400)
plugins/junit_rt/src/com/intellij/junit4/JUnit4IdeaTestRunner.java

index 49ff51dea24c8ffee890a863a91b311a91e07229..10f7da0ad4f4956eb655c0549370353c9c2fdc99 100644 (file)
  */
 package com.intellij.junit4;
 
-import com.intellij.rt.execution.junit.*;
+import com.intellij.rt.execution.junit.IDEAJUnitListener;
+import com.intellij.rt.execution.junit.IdeaTestRunner;
+import com.intellij.rt.execution.junit.TimeSender;
+import com.intellij.rt.execution.junit.TreeSender;
 import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
 import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
 import org.junit.internal.requests.ClassRequest;
@@ -25,7 +28,9 @@ import org.junit.runner.manipulation.Filter;
 import org.junit.runner.notification.RunListener;
 
 import java.lang.reflect.Field;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 /** @noinspection UnusedDeclaration*/
 public class JUnit4IdeaTestRunner implements IdeaTestRunner {
@@ -93,17 +98,20 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
     field.setAccessible(true);
     final Filter filter = (Filter)field.get(request);
     final String filterDescription = filter.describe();
-    if (filterDescription != null && (filterDescription.startsWith("Failed tests") || filterDescription.startsWith("Ignored"))) {
+    if (filterDescription != null) {
+      boolean isMethodFilter = filterDescription.startsWith("Method");
+      if (isMethodFilter && canCompress(description)) return (Description)description.getChildren().get(0);
       try {
         final Description failedTestsDescription = Description.createSuiteDescription(filterDescription, null);
-        for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext();) {
-          final Description childDescription = (Description)iterator.next();
-          if (filter.shouldRun(childDescription)) {
-            failedTestsDescription.addChild(childDescription);
+        if (filterDescription.startsWith("Tests") || filterDescription.startsWith("Ignored")) {
+          for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext(); ) {
+            final Description childDescription = (Description)iterator.next();
+            if (filter.shouldRun(childDescription)) {
+              failedTestsDescription.addChild(childDescription);
+            }
           }
-        }
-        description = failedTestsDescription;
-        if (!failedTestsDescription.isTest() && failedTestsDescription.testCount() == 1 && filterDescription.startsWith("Method")) {
+          description = failedTestsDescription;
+        } else  if (isMethodFilter && canCompress(failedTestsDescription)) {
           description = (Description)failedTestsDescription.getChildren().get(0);
         }
       }
@@ -114,6 +122,10 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
     return description;
   }
 
+  private static boolean canCompress(Description description) {
+    return !description.isTest() && description.testCount() == 1;
+  }
+
   private static Description getSuiteMethodDescription(Request request, Description description) throws NoSuchFieldException, IllegalAccessException {
     final Field field = ClassRequest.class.getDeclaredField("fTestClass");
     field.setAccessible(true);