You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2012/04/03 00:03:30 UTC

svn commit: r1308594 - in /lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat: TestExceptionInBeforeClassHooks.java TestSystemPropertiesInvariantRule.java WithNestedTests.java

Author: dweiss
Date: Mon Apr  2 22:03:30 2012
New Revision: 1308594

URL: http://svn.apache.org/viewvc?rev=1308594&view=rev
Log:
Ignore nested test suites if run from IDEs.

Modified:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java?rev=1308594&r1=1308593&r2=1308594&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java Mon Apr  2 22:03:30 2012
@@ -23,7 +23,6 @@ import java.util.regex.Pattern;
 
 import junit.framework.Assert;
 
-import org.apache.lucene.util.LuceneTestCase;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -51,7 +50,7 @@ public class TestExceptionInBeforeClassH
     public void test() {}
   }
 
-  public static class Nested2 extends LuceneTestCase {
+  public static class Nested2 extends WithNestedTests.AbstractNestedTest {
     public void test1() throws Exception {
       Thread t = new Thread() {
         public void run() {

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java?rev=1308594&r1=1308593&r2=1308594&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java Mon Apr  2 22:03:30 2012
@@ -19,7 +19,6 @@ package org.apache.lucene.util.junitcomp
 
 import java.util.Properties;
 
-import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.SystemPropertiesInvariantRule;
 import org.apache.lucene.util.SystemPropertiesRestoreRule;
 import org.junit.*;
@@ -40,7 +39,7 @@ public class TestSystemPropertiesInvaria
     super(true);
   }
   
-  public static class Base extends LuceneTestCase {
+  public static class Base extends WithNestedTests.AbstractNestedTest {
     public void testEmpty() {}
   }
   
@@ -102,6 +101,12 @@ public class TestSystemPropertiesInvaria
     }
   }
 
+  @Before
+  @After
+  public void cleanup() {
+    System.clearProperty(PROP_KEY1);
+  }
+  
   @Test
   public void testRuleInvariantBeforeClass() {
     Result runClasses = JUnitCore.runClasses(InBeforeClass.class);

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java?rev=1308594&r1=1308593&r2=1308594&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java Mon Apr  2 22:03:30 2012
@@ -24,8 +24,11 @@ import java.io.UnsupportedEncodingExcept
 import org.apache.lucene.util.LuceneTestCase;
 import org.junit.After;
 import org.junit.Assert;
-import org.junit.Assume;
 import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
 
 /**
  * An abstract test class that prepares nested test classes to run.
@@ -48,10 +51,18 @@ public abstract class WithNestedTests {
   };
 
   public static abstract class AbstractNestedTest extends LuceneTestCase {
-    @Before
-    public void before() {
-      Assume.assumeTrue(isRunningNested());
-    }
+    @ClassRule
+    public static TestRule ignoreIfRunAsStandalone = new TestRule() {
+      public Statement apply(final Statement s, Description arg1) {
+        return new Statement() {
+          public void evaluate() throws Throwable {
+            if (isRunningNested()) {
+              s.evaluate();
+            }
+          }
+        };
+      }
+    };
 
     protected static boolean isRunningNested() {
       return runsAsNested.get() != null && runsAsNested.get();