Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 99DE510AF7 for ; Mon, 14 Sep 2015 17:35:55 +0000 (UTC) Received: (qmail 52143 invoked by uid 500); 14 Sep 2015 17:35:43 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 52111 invoked by uid 500); 14 Sep 2015 17:35:42 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 52098 invoked by uid 99); 14 Sep 2015 17:35:42 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Sep 2015 17:35:42 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 73C5B180424 for ; Mon, 14 Sep 2015 17:35:42 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.774 X-Spam-Level: * X-Spam-Status: No, score=1.774 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.006] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Mg_uI3q8MCTA for ; Mon, 14 Sep 2015 17:35:40 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id ABE34204DD for ; Mon, 14 Sep 2015 17:35:39 +0000 (UTC) Received: (qmail 52032 invoked by uid 99); 14 Sep 2015 17:35:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Sep 2015 17:35:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9C172DFCE4; Mon, 14 Sep 2015 17:35:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.incubator.apache.org Date: Mon, 14 Sep 2015 17:35:38 -0000 Message-Id: <37c27daef70f43468ac4f98d084b7f56@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] incubator-geode git commit: Latest changes for using DUnitTestRule. Repository: incubator-geode Updated Branches: refs/heads/feature/GEODE-217 7c27657a0 -> 435dc63c1 http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/435dc63c/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestRule.java ---------------------------------------------------------------------- diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestRule.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestRule.java new file mode 100755 index 0000000..3d72b17 --- /dev/null +++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestRule.java @@ -0,0 +1,17 @@ +package com.gemstone.gemfire.test.junit.rules; + +import java.io.Serializable; + +import org.junit.rules.TestRule; + +/** + * Serializable version of JUnit TestRule. JUnit lifecycle is not + * executed in remote JVMs. + * + * The simplest way to satisfy this interface is to apply transient + * to every instance field. + * + * @author Kirk Lund + */ +public interface SerializableTestRule extends Serializable, TestRule { +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/435dc63c/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java ---------------------------------------------------------------------- diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java index 0992fe9..e0af5c0 100755 --- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java +++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java @@ -1,7 +1,5 @@ package com.gemstone.gemfire.test.junit.rules; -import java.io.Serializable; - import org.junit.rules.TestWatcher; /** @@ -11,5 +9,5 @@ import org.junit.rules.TestWatcher; * @author Kirk Lund */ @SuppressWarnings("serial") -public class SerializableTestWatcher extends TestWatcher implements Serializable { +public class SerializableTestWatcher extends TestWatcher implements SerializableTestRule { } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/435dc63c/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java ---------------------------------------------------------------------- diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java index 814ecea..e2b0ce2 100755 --- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java +++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java @@ -2,7 +2,6 @@ package com.gemstone.gemfire.test.junit.rules; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.io.Serializable; import java.lang.reflect.Field; import java.util.concurrent.TimeUnit; @@ -17,7 +16,7 @@ import org.junit.rules.Timeout; * @author Kirk Lund */ @SuppressWarnings("serial") -public class SerializableTimeout extends Timeout implements Serializable { +public class SerializableTimeout extends Timeout implements SerializableTestRule { public static Builder builder() { return new Builder(); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/435dc63c/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/tests/RuleAndClassRuleJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/tests/RuleAndClassRuleJUnitTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/tests/RuleAndClassRuleJUnitTest.java new file mode 100755 index 0000000..f02809c --- /dev/null +++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/tests/RuleAndClassRuleJUnitTest.java @@ -0,0 +1,122 @@ +package com.gemstone.gemfire.test.junit.rules.tests; + +import static com.gemstone.gemfire.test.junit.rules.tests.RunTest.*; +import static org.assertj.core.api.Assertions.*; + +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runner.Result; +import org.junit.runners.model.Statement; + +import com.gemstone.gemfire.test.junit.categories.UnitTest; + +@Category(UnitTest.class) +public class RuleAndClassRuleJUnitTest { + + @Test + public void usingRuleAsRuleAndClassRuleShouldInvokeBeforeClass() { + Result result = runTest(UsingRuleAsRuleAndClassRule.class); + + assertThat(result.wasSuccessful()).isTrue(); + assertThat(UsingRuleAsRuleAndClassRule.staticRule.beforeClassInvoked).isEqualTo(true); + } + + @Test + public void usingRuleAsRuleAndClassRuleShouldInvokeAfterClass() { + Result result = runTest(UsingRuleAsRuleAndClassRule.class); + + assertThat(result.wasSuccessful()).isTrue(); + assertThat(UsingRuleAsRuleAndClassRule.staticRule.afterClassInvoked).isEqualTo(true); + } + + @Test + public void usingRuleAsRuleAndClassRuleShouldInvokeBefore() { + Result result = runTest(UsingRuleAsRuleAndClassRule.class); + + assertThat(result.wasSuccessful()).isTrue(); + assertThat(UsingRuleAsRuleAndClassRule.staticRule.beforeInvoked).isEqualTo(true); + } + + @Test + public void usingRuleAsRuleAndClassRuleShouldInvokeAfter() { + Result result = runTest(UsingRuleAsRuleAndClassRule.class); + + assertThat(result.wasSuccessful()).isTrue(); + assertThat(UsingRuleAsRuleAndClassRule.staticRule.afterInvoked).isEqualTo(true); + } + + public static class SpyRule implements TestRule { + boolean beforeClassInvoked; + boolean afterClassInvoked; + boolean beforeInvoked; + boolean afterInvoked; + + @Override + public Statement apply(final Statement base, final Description description) { + if (description.isTest()) { + return statement(base); + } else if (description.isSuite()) { + return statementClass(base); + } + return base; + } + + private Statement statement(final Statement base) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + before(); + try { + base.evaluate(); + } finally { + after(); + } + } + }; + } + + private Statement statementClass(final Statement base) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + beforeClass(); + try { + base.evaluate(); + } finally { + afterClass(); + } + } + }; + } + + private void beforeClass() { + this.beforeClassInvoked = true; + } + + private void afterClass() { + this.afterClassInvoked = true; + } + + private void before() { + this.beforeInvoked = true; + } + + private void after() { + this.afterInvoked = true; + } + }; + + public static class UsingRuleAsRuleAndClassRule { + @ClassRule + public static SpyRule staticRule = new SpyRule(); + @Rule + public SpyRule rule = staticRule; + @Test + public void doTest() throws Exception { + } + } +}