From 20bff301113f4b6b10c9973fbe8db5fe71d63a28 Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Mon, 2 Apr 2012 22:03:30 +0000 Subject: [PATCH] Ignore nested test suites if run from IDEs. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1308594 13f79535-47bb-0310-9956-ffa450edef68 --- .../TestExceptionInBeforeClassHooks.java | 3 +-- .../TestSystemPropertiesInvariantRule.java | 9 ++++++-- .../util/junitcompat/WithNestedTests.java | 21 ++++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java index fa2798518f0..6a0b0d55e08 100644 --- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java +++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java @@ -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 TestExceptionInBeforeClassHooks extends WithNestedTests { 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() { diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java index f96af913803..76c8cb29513 100644 --- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java +++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java @@ -19,7 +19,6 @@ package org.apache.lucene.util.junitcompat; 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 TestSystemPropertiesInvariantRule extends WithNestedTests { super(true); } - public static class Base extends LuceneTestCase { + public static class Base extends WithNestedTests.AbstractNestedTest { public void testEmpty() {} } @@ -102,6 +101,12 @@ public class TestSystemPropertiesInvariantRule extends WithNestedTests { } } + @Before + @After + public void cleanup() { + System.clearProperty(PROP_KEY1); + } + @Test public void testRuleInvariantBeforeClass() { Result runClasses = JUnitCore.runClasses(InBeforeClass.class); diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java index b4bb9d96a39..145d945044d 100644 --- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java +++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java @@ -24,8 +24,11 @@ import java.io.UnsupportedEncodingException; 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();