You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/02/23 19:07:56 UTC
[5/5] incubator-geode git commit: Clean up
Clean up
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/7aba9ae0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/7aba9ae0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/7aba9ae0
Branch: refs/heads/feature/GEODE-953
Commit: 7aba9ae029e54258b5fdc333fa0e26d70583e4bf
Parents: f2487a4
Author: Kirk Lund <kl...@pivotal.io>
Authored: Tue Feb 23 09:44:59 2016 -0800
Committer: Kirk Lund <kl...@pivotal.io>
Committed: Tue Feb 23 09:44:59 2016 -0800
----------------------------------------------------------------------
.../gemfire/test/dunit/rules/RemoteInvoker.java | 9 +-
.../com/gemstone/gemfire/test/junit/Repeat.java | 2 +-
.../test/junit/categories/ContainerTest.java | 1 +
.../test/junit/categories/DistributedTest.java | 1 +
.../test/junit/categories/HydraTest.java | 1 +
.../test/junit/categories/IntegrationTest.java | 1 +
.../test/junit/categories/PerformanceTest.java | 1 +
.../gemfire/test/junit/categories/UITest.java | 1 +
.../gemfire/test/junit/categories/UnitTest.java | 12 +-
.../gemfire/test/junit/categories/WanTest.java | 1 +
.../test/junit/rules/ExpectedTimeoutRule.java | 43 ++-
.../gemfire/test/junit/rules/RuleList.java | 189 ++++-----
.../test/junit/rules/TestFixtureRule.java | 294 +++++++-------
.../rules/serializable/FieldsOfTestName.java | 2 +-
.../serializable/SerializableRuleList.java | 2 +-
.../SerializableTemporaryFolder.java | 1 -
.../serializable/SerializableTestRule.java | 3 -
.../serializable/SerializableTestWatcher.java | 4 +-
.../rules/serializable/SerializableTimeout.java | 12 +-
.../junit/support/DefaultIgnoreCondition.java | 2 +-
.../junit/rules/ExpectedTimeoutRuleTest.java | 73 +++-
.../test/junit/rules/IgnoreUntilRuleTest.java | 50 ++-
.../test/junit/rules/RepeatRuleTest.java | 157 ++++++--
.../rules/RetryRuleGlobalWithErrorTest.java | 138 +++++--
.../rules/RetryRuleGlobalWithExceptionTest.java | 142 +++++--
.../rules/RetryRuleLocalWithErrorTest.java | 115 ++++--
.../rules/RetryRuleLocalWithExceptionTest.java | 119 ++++--
.../gemfire/test/junit/rules/RuleListTest.java | 215 +++++++++++
.../test/junit/rules/TestFixtureRuleTest.java | 384 +++++++++++++++++++
.../gemfire/test/junit/rules/TestRunner.java | 6 +-
.../examples/RepeatingTestCasesExampleTest.java | 12 +-
.../rules/examples/RetryRuleExampleTest.java | 12 +-
.../rules/examples/RuleAndClassRuleTest.java | 19 +-
.../SerializableExternalResourceTest.java | 8 +-
.../serializable/SerializableRuleListTest.java | 11 +-
.../SerializableTemporaryFolderTest.java | 6 +-
.../SerializableTestFixtureRuleTest.java | 2 +-
.../serializable/SerializableTestNameTest.java | 9 +-
.../SerializableTestWatcherTest.java | 8 +-
.../serializable/SerializableTimeoutTest.java | 14 +-
40 files changed, 1592 insertions(+), 490 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
index 278250b..98dbc2f 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
@@ -24,13 +24,14 @@ import java.io.Serializable;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
/**
- * Provides remote invocation support to a <code>TestRule</code>. These
- * methods will invoke a SerializableRunnable in all remote DUnit JVMs
- * including the Locator JVM.
+ * Provides remote invocation support to a {@code TestRule}. These methods
+ * will invoke a SerializableRunnable in all remote DUnit JVMs including the
+ * Locator JVM.
*/
-@SuppressWarnings("serial")
class RemoteInvoker implements Serializable {
+ private static final long serialVersionUID = -1759722991299584649L;
+
public void invokeEverywhere(final SerializableRunnable runnable) {
try {
runnable.run();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Repeat.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Repeat.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Repeat.java
index 5cfa321..01434de 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Repeat.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Repeat.java
@@ -31,7 +31,7 @@ import java.lang.annotation.Target;
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
-@Target({ ElementType.METHOD })
+@Target(ElementType.METHOD)
@SuppressWarnings("unused")
public @interface Repeat {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/ContainerTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/ContainerTest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/ContainerTest.java
index 8eec738..dbafa34 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/ContainerTest.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/ContainerTest.java
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package com.gemstone.gemfire.test.junit.categories;
+
/**
* JUnit Test Category that specifies a test executes within a container
* environment such as an OSGi server.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/DistributedTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/DistributedTest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/DistributedTest.java
old mode 100644
new mode 100755
index 6aa538b..c9253f9
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/DistributedTest.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/DistributedTest.java
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package com.gemstone.gemfire.test.junit.categories;
+
/**
* JUnit Test Category that specifies a test involving multiple members of a
* distributed system.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/HydraTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/HydraTest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/HydraTest.java
index 4fe535b..ed21455 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/HydraTest.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/HydraTest.java
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package com.gemstone.gemfire.test.junit.categories;
+
/**
* JUnit Test Category that specifies a hydra test.
*
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/IntegrationTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/IntegrationTest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/IntegrationTest.java
old mode 100644
new mode 100755
index 1be6e45..eabc288
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/IntegrationTest.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/IntegrationTest.java
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package com.gemstone.gemfire.test.junit.categories;
+
/**
* JUnit Test Category that specifies a test involving inter-operation of
* components or subsystems.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/PerformanceTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/PerformanceTest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/PerformanceTest.java
old mode 100644
new mode 100755
index ad952be..7776112
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/PerformanceTest.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/PerformanceTest.java
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package com.gemstone.gemfire.test.junit.categories;
+
/**
* JUnit Test Category that specifies a test that measures performance.
*
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UITest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UITest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UITest.java
old mode 100644
new mode 100755
index 834931a..5f151cc
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UITest.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UITest.java
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package com.gemstone.gemfire.test.junit.categories;
+
/**
* JUnit Test Category that specifies a test involving a browser present to test the UI
*
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UnitTest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UnitTest.java
old mode 100644
new mode 100755
index d5be9e8..2d887c4
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UnitTest.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/UnitTest.java
@@ -15,11 +15,21 @@
* limitations under the License.
*/
package com.gemstone.gemfire.test.junit.categories;
+
/**
* JUnit Test Category that specifies a test with very narrow and well defined
* scope. Any complex dependencies and interactions are stubbed or mocked.
- *
+ *
+ * <p><ul>A {@code UnitTest} should <bold>not<bold> do any of the following:
+ * <li>communicate with a database
+ * <li>communicate across the network
+ * <li>access the file system
+ * <li>prevent the running of other unit tests in parallel
+ * <li>require anything special in the environment (such as editing config files or running an external process)
+ * </ul>
+ *
* @author Kirk Lund
+ * @see <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=126923">A Set of Unit Testing Rules by Michael Feathers</a>
*/
public interface UnitTest {
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/WanTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/WanTest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/WanTest.java
old mode 100644
new mode 100755
index 9abf15b..357e4ef
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/WanTest.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/categories/WanTest.java
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package com.gemstone.gemfire.test.junit.categories;
+
/**
* Tests Wan Feature.
*
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRule.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRule.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRule.java
index 7b6d345..3b02236 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRule.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRule.java
@@ -64,19 +64,30 @@ public class ExpectedTimeoutRule implements TestRule {
return this;
}
+ /**
+ * This method does nothing.
+ *
+ * @deprecated AssertionErrors are handled by default
+ */
+ @Deprecated
public ExpectedTimeoutRule handleAssertionErrors() {
this.delegate.handleAssertionErrors();
return this;
}
-
+
+ /**
+ * This method does nothing.
+ *
+ * @deprecated AssumptionViolatedExceptions are handled by default
+ */
+ @Deprecated
public ExpectedTimeoutRule handleAssumptionViolatedExceptions() {
this.delegate.handleAssumptionViolatedExceptions();
return this;
}
/**
- * Adds {@code matcher} to the list of requirements for any thrown
- * exception.
+ * Adds {@code matcher} to the list of requirements for any thrown exception.
*/
public void expect(final Matcher<?> matcher) {
this.delegate.expect(matcher);
@@ -84,7 +95,7 @@ public class ExpectedTimeoutRule implements TestRule {
/**
* Adds to the list of requirements for any thrown exception that it should
- * be an instance of {@code type}
+ * be an instance of {@code type}.
*/
public void expect(final Class<? extends Throwable> type) {
this.delegate.expect(type);
@@ -115,23 +126,29 @@ public class ExpectedTimeoutRule implements TestRule {
this.delegate.expectCause(expectedCause);
}
- public boolean expectsTimeout() {
- return minDuration > 0 || maxDuration > 0;
+ /**
+ * Returns true if a timeout is expected.
+ */
+ protected boolean expectsTimeout() {
+ return this.minDuration > 0 || this.maxDuration > 0;
}
-
- public boolean expectsThrowable() {
- return expectsThrowable = true;
+
+ /**
+ * Returns true if a Throwable is expected.
+ */
+ protected boolean expectsThrowable() {
+ return this.expectsThrowable;
}
@Override
public Statement apply(final Statement base, final Description description) {
- Statement next = delegate.apply(base, description);
+ Statement next = this.delegate.apply(base, description);
return new ExpectedTimeoutStatement(next);
}
private void handleTime(final Long duration) {
if (expectsTimeout()) {
- assertThat(timeUnit.convert(duration, TimeUnit.NANOSECONDS), new TimeMatcher(timeUnit, minDuration, maxDuration));
+ assertThat(this.timeUnit.convert(duration, TimeUnit.NANOSECONDS), new TimeMatcher(this.timeUnit, this.minDuration, this.maxDuration));
}
}
@@ -167,13 +184,13 @@ public class ExpectedTimeoutRule implements TestRule {
private final Statement next;
public ExpectedTimeoutStatement(final Statement base) {
- next = base;
+ this.next = base;
}
@Override
public void evaluate() throws Throwable {
long start = System.nanoTime();
- next.evaluate();
+ this.next.evaluate();
handleTime(System.nanoTime() - start);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java
index 08446b0..0431083 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java
@@ -1,92 +1,97 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gemstone.gemfire.test.junit.rules;
-
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The {@code RuleList} rule enables ordering of TestRules.
- *
- * <p>Example:
- *
- * <pre>
- * public class SomeTest {
- *
- * \@Rule
- * public RuleList rules = new RuleList().add(new FirstRule()
- * .add(new SecondRule()
- * .add(new ThirdRule();
- * </pre>
- *
- * @author Kirk Lund
- */
-public class RuleList implements TestRule {
-
- private final List<TestRule> rules = new ArrayList<>();
-
- /**
- * Creates an empty {@code RuleList}.
- */
- public RuleList() {
- }
-
- /**
- * Creates a {@code RuleList} containing a single {@link TestRule}.
- *
- * @param rule the first rule of the {@code RuleList}
- */
- public RuleList(final TestRule rule) {
- this.rules.add(rule);
- }
-
- /**
- * Creates a new {@code RuleList} containing the specified {@link TestRule}s.
- *
- * @param rules the list of {@code TestRule}s to add
- */
- protected RuleList(final List<TestRule> rules) {
- this.rules.addAll(rules);
- }
-
- /**
- * Adds a new {@code TestRule} to the end of the current {@code RuleList}.
- *
- * @param rule the rule to add.
- * @return the {@code RuleList} with a new TestRule added
- */
- public RuleList add(final TestRule rule) {
- this.rules.add(rule);
- return this;
- }
-
- @Override
- public Statement apply(Statement base, final Description description) {
- for (TestRule each : this.rules) {
- base = each.apply(base, description);
- }
- return base;
- }
-
- protected List<TestRule> rules() {
- return new ArrayList<>(this.rules);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.test.junit.rules;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * The {@code RuleList} rule enables ordering of TestRules.
+ *
+ * <p>Example:
+ *
+ * <pre>
+ * public class SomeTest {
+ *
+ * \@Rule
+ * public RuleList rules = new RuleList().add(new FirstRule()
+ * .add(new SecondRule()
+ * .add(new ThirdRule();
+ * </pre>
+ *
+ * @author Kirk Lund
+ */
+public class RuleList implements TestRule {
+
+ private final List<TestRule> rules = new ArrayList<>();
+
+ /**
+ * Creates an empty {@code RuleList}.
+ */
+ public RuleList() {
+ }
+
+ /**
+ * Creates a {@code RuleList} containing a single {@link TestRule}.
+ *
+ * @param rule the first rule of the {@code RuleList}
+ */
+ public RuleList(final TestRule rule) {
+ this.rules.add(rule);
+ }
+
+ /**
+ * Creates a new {@code RuleList} containing the specified {@link TestRule}s.
+ *
+ * @param rules the list of {@code TestRule}s to add
+ */
+ protected RuleList(final List<TestRule> rules) {
+ this.rules.addAll(rules);
+ }
+
+ /**
+ * Adds a new {@code TestRule} to the end of the current {@code RuleList}.
+ *
+ * @param rule the rule to add.
+ * @return the {@code RuleList} with a new TestRule added
+ */
+ public RuleList add(final TestRule rule) {
+ this.rules.add(rule);
+ return this;
+ }
+
+ @Override
+ public Statement apply(Statement base, final Description description) {
+ for (TestRule each : this.rules) {
+ base = each.apply(base, description);
+ }
+ return base;
+ }
+
+ /**
+ * Returns a reference to the actual list of {@code TestRule}s. For use by
+ * subclasses and tests.
+ */
+ protected List<TestRule> rules() {
+ return this.rules;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java
index 21e5eb9..7468c1f 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java
@@ -1,151 +1,143 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gemstone.gemfire.test.junit.rules;
-
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-/**
- * An abstract base class for test rules that combine {@code ClassRule} and
- * method {@code Rule} test fixture lifecycle callbacks. Subclasses may
- * override any or all of these methods:
- * <p><ul>
- * <li></li>{@link #beforeClass()}
- * <li></li>{@link #afterClass()}
- * <li></li>{@link #before()}
- * <li></li>{@link #after()}
- * </ul>
- *
- * <p>The rule variable does not have to be static in order to implement
- * {@link #beforeClass()} and {@link #afterClass()}.
- *
- * <p>Example:
- *
- * <pre>
- * public class SomeTest {
- *
- * \@Rule
- * public TestFixtureRule testFixtureRule = new TestFixtureRule() {
- * \@Override
- * protected void beforeClass() throws Throwable {
- * // setup executed once before all tests in SomeTest
- * }
- * \@Override
- * protected void afterClass() {
- * // teardown executed once after all tests in SomeTest
- * }
- * \@Override
- * protected void before() throws Throwable {
- * // setup executed before each test in SomeTest
- * }
- * \@Override
- * protected void after() {
- * // teardown executed after each test in SomeTest
- * }
- * }
- * }
- * </pre>
- *
- * @author Kirk Lund
- */
-public class TestFixtureRule implements TestRule {
-
- @Override
- public Statement apply(final Statement base, final Description description) {
- if (description.isSuite()) {
- return createClassStatement(base);
- } else if (description.isTest()) {
- return createMethodStatement(base);
- }
- return base;
- }
-
- /**
- * Returns new <code>Statement</code> for invoking <code>beforeClass</code>
- * and <code>afterClass</code>.
- */
- protected Statement createClassStatement(final Statement base) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- beforeClass();
- try {
- base.evaluate();
- } finally {
- afterClass();
- }
- }
- };
- }
-
- /**
- * Returns new <code>Statement</code> for invoking <code>before</code>
- * and <code>after</code>.
- */
- protected Statement createMethodStatement(final Statement base) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- before();
- try {
- base.evaluate();
- } finally {
- after();
- }
- }
- };
- }
-
- /**
- * Override to perform custom setup during <code>beforeClass</code> which
- * is invoked prior to {@link #before()} and all test methods.
- *
- * If any <code>Throwable</code> is thrown, then <code>afterClass</code> will
- * be disabled.
- *
- * @throws Throwable if setup fails
- */
- protected void beforeClass() throws Throwable {
- }
-
- /**
- * Override to perform custom tearDown during <code>afterClass</code> which
- * is invoked following {@link #after()} and all test methods.
- */
- protected void afterClass() {
- }
-
- /**
- * Override to perform custom setup before each test method.
- *
- * If any <code>Throwable</code> is thrown, then <code>after</code> will
- * be disabled.
- *
- * @throws Throwable if setup fails
- */
- protected void before() throws Throwable {
- // do nothing
- }
-
- /**
- * Override to perform custom tearDown during after each test method.
- */
- protected void after() {
- // do nothing
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.test.junit.rules;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * An abstract base class for test rules that combine {@code ClassRule} and
+ * method {@code Rule} test fixture lifecycle callbacks. Subclasses may
+ * override any or all of these methods:
+ * <p><ul>
+ * <li>{@link #beforeClass()}
+ * <li>{@link #afterClass()}
+ * <li>{@link #before()}
+ * <li>{@link #after()}
+ * </ul>
+ *
+ * <p>The rule variable does not have to be static in order to implement
+ * {@link #beforeClass()} and {@link #afterClass()}.
+ *
+ * <p>Example:
+ *
+ * <pre>
+ * public class SomeTest {
+ *
+ * \@Rule
+ * public TestFixtureRule testFixtureRule = new TestFixtureRule() {
+ * \@Override
+ * protected void beforeClass() throws Throwable {
+ * // setup executed once before all tests in SomeTest
+ * }
+ * \@Override
+ * protected void afterClass() {
+ * // teardown executed once after all tests in SomeTest
+ * }
+ * \@Override
+ * protected void before() throws Throwable {
+ * // setup executed before each test in SomeTest
+ * }
+ * \@Override
+ * protected void after() {
+ * // teardown executed after each test in SomeTest
+ * }
+ * }
+ * }
+ * </pre>
+ */
+public class TestFixtureRule implements TestRule {
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ if (description.isSuite()) {
+ return createClassStatement(base);
+ } else if (description.isTest()) {
+ return createMethodStatement(base);
+ }
+ return base;
+ }
+
+ /**
+ * Returns new <code>Statement</code> for invoking <code>beforeClass</code>
+ * and <code>afterClass</code>.
+ */
+ protected Statement createClassStatement(final Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ beforeClass();
+ try {
+ base.evaluate();
+ } finally {
+ afterClass();
+ }
+ }
+ };
+ }
+
+ /**
+ * Returns new <code>Statement</code> for invoking <code>before</code>
+ * and <code>after</code>.
+ */
+ protected Statement createMethodStatement(final Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ before();
+ try {
+ base.evaluate();
+ } finally {
+ after();
+ }
+ }
+ };
+ }
+
+ /**
+ * Override to perform custom setup during <code>beforeClass</code> which
+ * is invoked prior to {@link #before()} and all test methods.
+ *
+ * @throws Throwable if setup fails
+ */
+ protected void beforeClass() throws Throwable {
+ }
+
+ /**
+ * Override to perform custom tearDown during <code>afterClass</code> which
+ * is invoked following {@link #after()} and all test methods.
+ */
+ protected void afterClass() {
+ }
+
+ /**
+ * Override to perform custom setup before each test method.
+ *
+ * @throws Throwable if setup fails
+ */
+ protected void before() throws Throwable {
+ // do nothing
+ }
+
+ /**
+ * Override to perform custom tearDown during after each test method.
+ */
+ protected void after() {
+ // do nothing
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java
index 3a2e4bb..f30ed10 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java
@@ -19,6 +19,6 @@ package com.gemstone.gemfire.test.junit.rules.serializable;
/**
* Names of member fields in {@link org.junit.rules.TestName}.
*/
-public interface FieldsOfTestName {
+interface FieldsOfTestName {
static final String FIELD_NAME = "name"; // String
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java
index b1bbf83..3ae3079 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java
@@ -37,7 +37,7 @@ public class SerializableRuleList extends RuleList implements SerializableTestRu
super(rule);
}
- public SerializableRuleList(final List<TestRule> rules) {
+ protected SerializableRuleList(final List<TestRule> rules) {
super(rules);
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java
index 6fb01cd..390cdc7 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java
@@ -53,7 +53,6 @@ public class SerializableTemporaryFolder extends TemporaryFolder implements Seri
*/
private static class SerializationProxy implements Serializable {
- private static final long serialVersionUID = 1905526044015078240L;
private final File parentFolder;
private final File folder;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java
index f910c14..9d06bc6 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java
@@ -23,9 +23,6 @@ import org.junit.rules.TestRule;
/**
* Specifies that a {@link org.junit.rules.TestRule TestRule} is
* {@code Serializable}.
- *
- * The simplest way to satisfy this interface is to apply {@code transient} to
- * every instance field.
*/
public interface SerializableTestRule extends Serializable, TestRule {
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java
index 6292d7c..d325b09 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java
@@ -19,8 +19,8 @@ package com.gemstone.gemfire.test.junit.rules.serializable;
import org.junit.rules.TestWatcher;
/**
- * Serializable subclass of {@link org.junit.rules.TestWatcher TestWatcher}. No
- * instance variables are serialized.
+ * Serializable subclass of {@link org.junit.rules.TestWatcher TestWatcher}.
+ * There are no instance variables to be serialized.
*/
public abstract class SerializableTestWatcher extends TestWatcher implements SerializableTestRule {
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java
index e77120d..f3a4ba7 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java
@@ -36,14 +36,10 @@ public class SerializableTimeout extends Timeout implements SerializableTestRule
return new Builder();
}
- public SerializableTimeout() {
- this(builder());
- }
-
public SerializableTimeout(final long timeout, final TimeUnit timeUnit) {
super(timeout, timeUnit);
}
-
+
protected SerializableTimeout(final Builder builder) {
super(builder);
}
@@ -72,11 +68,11 @@ public class SerializableTimeout extends Timeout implements SerializableTestRule
}
@Override
- public Builder withLookingForStuckThread(boolean enable) {
+ public Builder withLookingForStuckThread(final boolean enable) {
super.withLookingForStuckThread(enable);
return this;
}
-
+
@Override
public SerializableTimeout build() {
return new SerializableTimeout(this);
@@ -92,7 +88,7 @@ public class SerializableTimeout extends Timeout implements SerializableTestRule
private final TimeUnit timeUnit;
private final boolean lookForStuckThread;
- SerializationProxy(SerializableTimeout instance) {
+ SerializationProxy(final SerializableTimeout instance) {
this.timeout = (long) readField(Timeout.class, instance, FIELD_TIMEOUT);
this.timeUnit =(TimeUnit) readField(Timeout.class, instance, FIELD_TIME_UNIT);
this.lookForStuckThread =(boolean) readField(Timeout.class, instance, FIELD_LOOK_FOR_STUCK_THREAD);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/support/DefaultIgnoreCondition.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/support/DefaultIgnoreCondition.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/support/DefaultIgnoreCondition.java
index b721c41..67177d2 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/support/DefaultIgnoreCondition.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/support/DefaultIgnoreCondition.java
@@ -46,7 +46,7 @@ public class DefaultIgnoreCondition implements IgnoreCondition {
}
public boolean isIgnore() {
- return ignore;
+ return this.ignore;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRuleTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRuleTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRuleTest.java
index f2191f0..5a0d45c 100755
--- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRuleTest.java
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeoutRuleTest.java
@@ -123,29 +123,46 @@ public class ExpectedTimeoutRuleTest {
Failure failure = failures.get(0);
assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class).hasMessage("Expected test to throw (an instance of " + TimeoutException.class.getName() + " and exception with message a string containing \"" + FailsWhenTimeoutIsLate.message + "\")");
}
-
+
+ /**
+ * Base class for all inner class test cases
+ */
public static class AbstractExpectedTimeoutRuleTest {
+
@Rule
public ExpectedTimeoutRule timeout = ExpectedTimeoutRule.none();
}
-
+
+ /**
+ * Used by test {@link #passesUnused()}
+ */
public static class PassingTestShouldPassWhenUnused extends AbstractExpectedTimeoutRuleTest {
+
@Test
- public void passesUnused() throws Exception {
+ public void doTest() {
}
}
-
+
+ /**
+ * Used by test {@link #failsWithoutExpectedException()}
+ */
public static class FailsWithoutExpectedException extends AbstractExpectedTimeoutRuleTest {
+
@Test
- public void failsWithoutExpectedException() throws Exception {
+ public void doTest() {
timeout.expect(TimeoutException.class);
}
}
-
+
+ /**
+ * Used by test {@link #failsWithoutExpectedTimeoutException()}
+ */
public static class FailsWithoutExpectedTimeoutException extends AbstractExpectedTimeoutRuleTest {
- public static final String message = "this is a message for FailsWithoutExpectedTimeoutException";
+
+ static final String message = "this is a message for FailsWithoutExpectedTimeoutException";
+
@Test
- public void failsWithoutExpectedTimeoutAndTimeoutException() throws Exception {
+ public void doTest() throws Exception {
timeout.expect(TimeoutException.class);
timeout.expectMessage(message);
timeout.expectMinimumDuration(10);
@@ -154,11 +171,16 @@ public class ExpectedTimeoutRuleTest {
Thread.sleep(100);
}
}
-
+
+ /**
+ * Used by test {@link #failsWithExpectedTimeoutButWrongError()}
+ */
public static class FailsWithExpectedTimeoutButWrongError extends AbstractExpectedTimeoutRuleTest {
- public static final String message = "this is a message for FailsWithExpectedTimeoutButWrongError";
+
+ static final String message = "this is a message for FailsWithExpectedTimeoutButWrongError";
+
@Test
- public void failsWithExpectedTimeoutButWrongError() throws Exception {
+ public void doTest() throws Exception {
timeout.expect(TimeoutException.class);
timeout.expectMessage(message);
timeout.expectMinimumDuration(10);
@@ -169,11 +191,16 @@ public class ExpectedTimeoutRuleTest {
}
}
+ /**
+ * Used by test {@link #passesWithExpectedTimeoutAndTimeoutException()}
+ */
public static class PassesWithExpectedTimeoutAndTimeoutException extends AbstractExpectedTimeoutRuleTest {
- public static final String message = "this is a message for PassesWithExpectedTimeoutAndTimeoutException";
- public static final Class<TimeoutException> exceptionClass = TimeoutException.class;
+
+ static final String message = "this is a message for PassesWithExpectedTimeoutAndTimeoutException";
+ static final Class<TimeoutException> exceptionClass = TimeoutException.class;
+
@Test
- public void passesWithExpectedTimeoutAndTimeoutException() throws Exception {
+ public void doTest() throws Exception {
timeout.expect(exceptionClass);
timeout.expectMessage(message);
timeout.expectMinimumDuration(10);
@@ -184,10 +211,15 @@ public class ExpectedTimeoutRuleTest {
}
}
+ /**
+ * Used by test {@link #failsWhenTimeoutIsEarly()}
+ */
public static class FailsWhenTimeoutIsEarly extends AbstractExpectedTimeoutRuleTest {
- public static final String message = "this is a message for FailsWhenTimeoutIsEarly";
+
+ static final String message = "this is a message for FailsWhenTimeoutIsEarly";
+
@Test
- public void failsWhenTimeoutIsEarly() throws Exception {
+ public void doTest() throws Exception {
timeout.expect(TimeoutException.class);
timeout.expectMessage(message);
timeout.expectMinimumDuration(1000);
@@ -197,10 +229,15 @@ public class ExpectedTimeoutRuleTest {
}
}
+ /**
+ * Used by test {@link #failsWhenTimeoutIsLate()}
+ */
public static class FailsWhenTimeoutIsLate extends AbstractExpectedTimeoutRuleTest {
- public static final String message = "this is a message for FailsWhenTimeoutIsLate";
+
+ static final String message = "this is a message for FailsWhenTimeoutIsLate";
+
@Test
- public void failsWhenTimeoutIsLate() throws Exception {
+ public void doTest() throws Exception {
timeout.expect(TimeoutException.class);
timeout.expectMessage(message);
timeout.expectMinimumDuration(10);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/IgnoreUntilRuleTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/IgnoreUntilRuleTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/IgnoreUntilRuleTest.java
index 568bec5..9d99971 100755
--- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/IgnoreUntilRuleTest.java
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/IgnoreUntilRuleTest.java
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
import java.util.List;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -74,13 +75,22 @@ public class IgnoreUntilRuleTest {
assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class).hasMessage(ASSERTION_ERROR_MESSAGE);
assertThat(ShouldExecuteWhenUntilIsDefault.count).isEqualTo(1);
}
-
+
+ /**
+ * Used by test {@link #shouldIgnoreWhenUntilIsInFuture()}
+ */
public static class ShouldIgnoreWhenUntilIsInFuture {
- private static int count;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public final IgnoreUntilRule ignoreUntilRule = new IgnoreUntilRule();
-
+
@Test
@IgnoreUntil(value = "description", until = "3000-01-01")
public void doTest() throws Exception {
@@ -89,12 +99,21 @@ public class IgnoreUntilRuleTest {
}
}
+ /**
+ * Used by test {@link #shouldExecuteWhenUntilIsInPast()}
+ */
public static class ShouldExecuteWhenUntilIsInPast {
- private static int count;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public final IgnoreUntilRule ignoreUntilRule = new IgnoreUntilRule();
-
+
@Test
@IgnoreUntil(value = "description", until = "1980-01-01")
public void doTest() throws Exception {
@@ -103,14 +122,23 @@ public class IgnoreUntilRuleTest {
}
}
+ /**
+ * Used by test {@link #shouldExecuteWhenUntilIsDefault()}
+ */
public static class ShouldExecuteWhenUntilIsDefault {
- private static int count;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public final IgnoreUntilRule ignoreUntilRule = new IgnoreUntilRule();
-
+
@Test
- @IgnoreUntil(value = "description")
+ @IgnoreUntil("description")
public void doTest() throws Exception {
count++;
fail(ASSERTION_ERROR_MESSAGE);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RepeatRuleTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RepeatRuleTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RepeatRuleTest.java
index e17bc51..e22a87a 100755
--- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RepeatRuleTest.java
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RepeatRuleTest.java
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
import java.util.List;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -89,6 +90,17 @@ public class RepeatRuleTest {
assertThat(NegativeValueShouldThrowIllegalArgumentException.count).isEqualTo(0);
}
+ /**
+ * Characterizes the behavior but is not a requirement for {@code RepeatRule}.
+ */
+ @Test
+ public void passingTestShouldBeSkippedWhenRepeatIsZero() {
+ Result result = TestRunner.runTest(PassingTestShouldBeSkippedWhenRepeatIsZero.class);
+
+ assertThat(result.wasSuccessful()).isFalse();
+ assertThat(PassingTestShouldBeSkippedWhenRepeatIsZero.count).isEqualTo(0);
+ }
+
@Test
public void failingTestShouldFailOneTimeWhenRepeatIsOne() {
Result result = TestRunner.runTest(FailingTestShouldFailOneTimeWhenRepeatIsOne.class);
@@ -155,9 +167,18 @@ public class RepeatRuleTest {
assertThat(PassingTestShouldPassThreeTimesWhenRepeatIsThree.count).isEqualTo(3);
}
+ /**
+ * Used by test {@link #failingTestShouldFailOneTimeWhenRepeatIsUnused()}
+ */
public static class FailingTestShouldFailOneTimeWhenRepeatIsUnused {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -168,9 +189,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #passingTestShouldPassOneTimeWhenRepeatIsUnused()}
+ */
public static class PassingTestShouldPassOneTimeWhenRepeatIsUnused {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -180,9 +210,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #zeroValueShouldThrowIllegalArgumentException()}
+ */
public static class ZeroValueShouldThrowIllegalArgumentException {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -193,9 +232,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #negativeValueShouldThrowIllegalArgumentException()}
+ */
public static class NegativeValueShouldThrowIllegalArgumentException {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -206,9 +254,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #passingTestShouldBeSkippedWhenRepeatIsZero()}
+ */
public static class PassingTestShouldBeSkippedWhenRepeatIsZero {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -218,10 +275,19 @@ public class RepeatRuleTest {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #failingTestShouldFailOneTimeWhenRepeatIsOne()}
+ */
public static class FailingTestShouldFailOneTimeWhenRepeatIsOne {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -233,9 +299,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #passingTestShouldPassOneTimeWhenRepeatIsOne()}
+ */
public static class PassingTestShouldPassOneTimeWhenRepeatIsOne {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -246,9 +321,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #failingTestShouldFailOneTimeWhenRepeatIsTwo()}
+ */
public static class FailingTestShouldFailOneTimeWhenRepeatIsTwo {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -260,9 +344,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #passingTestShouldPassTwoTimesWhenRepeatIsTwo()}
+ */
public static class PassingTestShouldPassTwoTimesWhenRepeatIsTwo {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -273,9 +366,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #failingTestShouldFailOneTimeWhenRepeatIsThree()}
+ */
public static class FailingTestShouldFailOneTimeWhenRepeatIsThree {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
@@ -287,9 +389,18 @@ public class RepeatRuleTest {
}
}
+ /**
+ * Used by test {@link #passingTestShouldPassThreeTimesWhenRepeatIsThree()}
+ */
public static class PassingTestShouldPassThreeTimesWhenRepeatIsThree {
- protected static int count = 0;
-
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
+
@Rule
public RepeatRule repeat = new RepeatRule();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithErrorTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithErrorTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithErrorTest.java
index ee51c4e..75d5a60 100755
--- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithErrorTest.java
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithErrorTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.fail;
import java.util.List;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -127,85 +128,142 @@ public class RetryRuleGlobalWithErrorTest {
assertThat(result.wasSuccessful()).isTrue();
assertThat(PassesOnThirdAttempt.count).isEqualTo(3);
}
-
+
+ /**
+ * Used by test {@link #zeroIsIllegal()}
+ */
public static class ZeroIsIllegal {
- protected static int count;
- protected static final String message = "Retry count must be greater than zero";
+
+ static final String message = "Retry count must be greater than zero";
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
@Rule
public RetryRule retryRule = new RetryRule(0);
@Test
- public void zeroIsIllegal() throws Exception {
+ public void doTest() throws Exception {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #failsWithOne()}
+ */
public static class FailsWithOne {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(1);
@Test
- public void failsWithOne() throws Exception {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
fail(message);
}
}
-
+
+ /**
+ * Used by test {@link #passesWithOne()}
+ */
public static class PassesWithOne {
- protected static int count;
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
@Rule
public RetryRule retryRule = new RetryRule(1);
@Test
- public void passesWithOne() throws Exception {
+ public void doTest() throws Exception {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #passesWithUnused()}
+ */
public static class PassesWhenUnused {
- protected static int count;
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
@Rule
public RetryRule retryRule = new RetryRule(2);
@Test
- public void passesWithUnused() throws Exception {
+ public void doTest() throws Exception {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #failsOnSecondAttempt()}
+ */
public static class FailsOnSecondAttempt {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(2);
@Test
@Retry(2)
- public void failsOnSecondAttempt() {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
fail(message);
}
}
-
+
+ /**
+ * Used by test {@link #passesOnSecondAttempt()}
+ */
public static class PassesOnSecondAttempt {
- protected static int count;
- protected static String message;
-
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
+
@Rule
public RetryRule retryRule = new RetryRule(2);
@Test
@Retry(2)
- public void failsOnSecondAttempt() {
+ public void doTest() throws Exception {
count++;
if (count < 2) {
message = "Failing " + count;
@@ -213,32 +271,52 @@ public class RetryRuleGlobalWithErrorTest {
}
}
}
-
+
+ /**
+ * Used by test {@link #failsOnThirdAttempt()}
+ */
public static class FailsOnThirdAttempt {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(3);
@Test
@Retry(3)
- public void failsOnThirdAttempt() {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
fail(message);
}
}
+ /**
+ * Used by test {@link #passesOnThirdAttempt()}
+ */
public static class PassesOnThirdAttempt {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(3);
@Test
- public void failsOnThirdAttempt() {
+ public void doTest() throws Exception {
count++;
if (count < 3) {
message = "Failing " + count;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithExceptionTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithExceptionTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithExceptionTest.java
index 4afa2c2..b060820 100755
--- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithExceptionTest.java
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleGlobalWithExceptionTest.java
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
import java.util.List;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -124,92 +125,151 @@ public class RetryRuleGlobalWithExceptionTest {
assertThat(result.wasSuccessful()).isTrue();
assertThat(PassesOnThirdAttempt.count).isEqualTo(3);
}
-
+
+ /**
+ * Custom exception used by several tests
+ */
public static class CustomException extends Exception {
- private static final long serialVersionUID = 1L;
public CustomException(final String message) {
super(message);
}
}
-
+
+ /**
+ * Used by test {@link #zeroIsIllegal()}
+ */
public static class ZeroIsIllegal {
- protected static int count;
- protected static final String message = "Retry count must be greater than zero";
+
+ static int count = 0;
+ static final String message = "Retry count must be greater than zero";
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
@Rule
public RetryRule retryRule = new RetryRule(0);
@Test
- public void zeroIsIllegal() throws Exception {
+ public void doTest() throws Exception {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #failsWithOne()}
+ */
public static class FailsWithOne {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(1);
@Test
- public void failsWithOne() throws Exception {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
throw new CustomException(message);
}
}
-
+
+ /**
+ * Used by test {@link #passesWithOne()}
+ */
public static class PassesWithOne {
- protected static int count;
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
@Rule
public RetryRule retryRule = new RetryRule(1);
@Test
- public void passesWithOne() throws Exception {
+ public void doTest() throws Exception {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #passesWithUnused()}
+ */
public static class PassesWhenUnused {
- protected static int count;
+
+ static int count = 0;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ }
@Rule
public RetryRule retryRule = new RetryRule(2);
@Test
- public void passesWithUnused() throws Exception {
+ public void doTest() throws Exception {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #failsOnSecondAttempt()}
+ */
public static class FailsOnSecondAttempt {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(2);
@Test
@Retry(2)
- public void failsOnSecondAttempt() throws Exception {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
throw new CustomException(message);
}
}
-
+
+ /**
+ * Used by test {@link #passesOnSecondAttempt()}
+ */
public static class PassesOnSecondAttempt {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(2);
@Test
@Retry(2)
- public void failsOnSecondAttempt() throws Exception {
+ public void doTest() throws Exception {
count++;
if (count < 2) {
message = "Failing " + count;
@@ -217,32 +277,52 @@ public class RetryRuleGlobalWithExceptionTest {
}
}
}
-
+
+ /**
+ * Used by test {@link #failsOnThirdAttempt()}
+ */
public static class FailsOnThirdAttempt {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(3);
@Test
@Retry(3)
- public void failsOnThirdAttempt() throws Exception {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
throw new CustomException(message);
}
}
+ /**
+ * Used by test {@link #passesOnThirdAttempt()}
+ */
public static class PassesOnThirdAttempt {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule(3);
@Test
- public void failsOnThirdAttempt() throws Exception {
+ public void doTest() throws Exception {
count++;
if (count < 3) {
message = "Failing " + count;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithErrorTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithErrorTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithErrorTest.java
index ad3c258..a57462e 100755
--- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithErrorTest.java
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithErrorTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.fail;
import java.util.List;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -105,61 +106,101 @@ public class RetryRuleLocalWithErrorTest {
assertThat(result.wasSuccessful()).isTrue();
assertThat(PassesOnThirdAttempt.count).isEqualTo(3);
}
-
+
+ /**
+ * Used by test {@link #failsUnused()}
+ */
public static class FailsUnused {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule();
@Test
- public void failsUnused() throws Exception {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
fail(message);
}
}
-
+
+ /**
+ * Used by test {@link #passesUnused()}
+ */
public static class PassesUnused {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule();
@Test
- public void passesUnused() throws Exception {
+ public void doTest() throws Exception {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #failsOnSecondAttempt()}
+ */
public static class FailsOnSecondAttempt {
- protected static int count;
- protected static String message;
-
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
+
@Rule
public RetryRule retryRule = new RetryRule();
@Test
@Retry(2)
- public void failsOnSecondAttempt() {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
fail(message);
}
}
-
+
+ /**
+ * Used by test {@link #passesOnSecondAttempt()}
+ */
public static class PassesOnSecondAttempt {
- protected static int count;
- protected static String message;
-
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
+
@Rule
public RetryRule retryRule = new RetryRule();
@Test
@Retry(2)
- public void failsOnSecondAttempt() {
+ public void doTest() throws Exception {
count++;
if (count < 2) {
message = "Failing " + count;
@@ -167,17 +208,27 @@ public class RetryRuleLocalWithErrorTest {
}
}
}
-
+
+ /**
+ * Used by test {@link #failsOnThirdAttempt()}
+ */
public static class FailsOnThirdAttempt {
- protected static int count;
- protected static String message;
-
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
+
@Rule
public RetryRule retryRule = new RetryRule();
@Test
@Retry(3)
- public void failsOnThirdAttempt() {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
@@ -185,16 +236,26 @@ public class RetryRuleLocalWithErrorTest {
}
}
+ /**
+ * Used by test {@link #passesOnThirdAttempt()}
+ */
public static class PassesOnThirdAttempt {
- protected static int count;
- protected static String message;
-
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
+
@Rule
public RetryRule retryRule = new RetryRule();
@Test
@Retry(3)
- public void failsOnThirdAttempt() {
+ public void doTest() throws Exception {
count++;
if (count < 3) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithExceptionTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithExceptionTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithExceptionTest.java
index 00363dd..48e34d2 100755
--- a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithExceptionTest.java
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RetryRuleLocalWithExceptionTest.java
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
import java.util.List;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -106,68 +107,110 @@ public class RetryRuleLocalWithExceptionTest {
assertThat(result.wasSuccessful()).isTrue();
assertThat(PassesOnThirdAttempt.count).isEqualTo(3);
}
-
+
+ /**
+ * Custom exception used by several tests
+ */
public static class CustomException extends Exception {
- private static final long serialVersionUID = 1L;
public CustomException(final String message) {
super(message);
}
}
-
+
+ /**
+ * Used by test {@link #failsUnused()}
+ */
public static class FailsUnused {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule();
@Test
- public void failsUnused() throws Exception {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
throw new CustomException(message);
}
}
-
+
+ /**
+ * Used by test {@link #passesUnused()}
+ */
public static class PassesUnused {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule();
@Test
- public void passesUnused() throws Exception {
+ public void doTest() throws Exception {
count++;
}
}
-
+
+ /**
+ * Used by test {@link #failsOnSecondAttempt()}
+ */
public static class FailsOnSecondAttempt {
- protected static int count;
- protected static String message;
-
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
+
@Rule
public RetryRule retryRule = new RetryRule();
@Test
@Retry(2)
- public void failsOnSecondAttempt() throws Exception {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
throw new CustomException(message);
}
}
-
+
+ /**
+ * Used by test {@link #passesOnSecondAttempt()}
+ */
public static class PassesOnSecondAttempt {
- protected static int count;
- protected static String message;
-
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
+
@Rule
public RetryRule retryRule = new RetryRule();
@Test
@Retry(2)
- public void failsOnSecondAttempt() throws Exception {
+ public void doTest() throws Exception {
count++;
if (count < 2) {
message = "Failing " + count;
@@ -175,17 +218,27 @@ public class RetryRuleLocalWithExceptionTest {
}
}
}
-
+
+ /**
+ * Used by test {@link #failsOnThirdAttempt()}
+ */
public static class FailsOnThirdAttempt {
- protected static int count;
- protected static String message;
-
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
+
@Rule
public RetryRule retryRule = new RetryRule();
@Test
@Retry(3)
- public void failsOnThirdAttempt() throws Exception {
+ public void doTest() throws Exception {
count++;
message = "Failing " + count;
@@ -193,16 +246,26 @@ public class RetryRuleLocalWithExceptionTest {
}
}
+ /**
+ * Used by test {@link #passesOnThirdAttempt()}
+ */
public static class PassesOnThirdAttempt {
- protected static int count;
- protected static String message;
+
+ static int count = 0;
+ static String message = null;
+
+ @BeforeClass
+ public static void beforeClass() {
+ count = 0;
+ message = null;
+ }
@Rule
public RetryRule retryRule = new RetryRule();
@Test
@Retry(3)
- public void failsOnThirdAttempt() throws Exception {
+ public void doTest() throws Exception {
count++;
if (count < 3) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7aba9ae0/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RuleListTest.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RuleListTest.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RuleListTest.java
new file mode 100755
index 0000000..0ae23f1
--- /dev/null
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/RuleListTest.java
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.test.junit.rules;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExternalResource;
+import org.junit.runner.Result;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Unit tests for {@link RuleList}.
+ */
+public class RuleListTest {
+
+ private static AtomicInteger counter;
+ private static Invocations[] invocations;
+
+ @BeforeClass
+ public static void setUpClass() {
+ counter = new AtomicInteger();
+ invocations = new Invocations[] { new Invocations(counter), new Invocations(counter), new Invocations(counter) };
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ counter = null;
+ invocations = null;
+ ThreeRules.ruleListStatic = null;
+ }
+
+ @Test
+ public void firstShouldBeFirstBeforeLastAfter() {
+ Result result = TestRunner.runTest(ThreeRules.class);
+
+ assertThat(result.wasSuccessful()).isTrue();
+
+ assertThat(counter.get()).isEqualTo(9);
+
+ assertThat(invocations[0].beforeInvocation).isEqualTo(1);
+ assertThat(invocations[1].beforeInvocation).isEqualTo(2);
+ assertThat(invocations[2].beforeInvocation).isEqualTo(3);
+
+ assertThat(invocations[0].testInvocation).isEqualTo(4);
+ assertThat(invocations[1].testInvocation).isEqualTo(5);
+ assertThat(invocations[2].testInvocation).isEqualTo(6);
+
+ assertThat(invocations[2].afterInvocation).isEqualTo(7);
+ assertThat(invocations[1].afterInvocation).isEqualTo(8);
+ assertThat(invocations[0].afterInvocation).isEqualTo(9);
+ }
+
+ /**
+ * Used by test {@link #firstShouldBeFirstBeforeLastAfter()}
+ */
+ public static class ThreeRules {
+
+ static RuleList ruleListStatic;
+
+ public SpyRule ruleOne = new SpyRule("ruleOne", invocations[0]);
+ public SpyRule ruleTwo = new SpyRule("ruleTwo", invocations[1]);
+ public SpyRule ruleThree = new SpyRule("ruleThree", invocations[2]);
+
+ @Rule
+ public RuleList ruleList = new RuleList().add(ruleThree).add(ruleTwo).add(ruleOne);
+
+ @Test
+ public void doTest() throws Exception {
+ ruleListStatic = ruleList;
+ invocations[0].invokedTest();
+ invocations[1].invokedTest();
+ invocations[2].invokedTest();
+ }
+ }
+
+ /**
+ * Structure of rule callback and test invocations
+ */
+ public static class Invocations {
+
+ private final AtomicInteger counter;
+ int beforeInvocation = 0;
+ int testInvocation = 0;
+ int afterInvocation = 0;
+
+ Invocations(AtomicInteger counter) {
+ this.counter = counter;
+ }
+
+ void invokedTest() {
+ testInvocation = counter.incrementAndGet();
+ }
+ void invokedBefore() {
+ beforeInvocation = counter.incrementAndGet();
+ }
+ void invokedAfter() {
+ afterInvocation = counter.incrementAndGet();
+ }
+
+ @Override
+ public String toString() {
+ return "Invocations{" + "counter=" + counter + ", beforeInvocation=" + beforeInvocation + ", testInvocation=" + testInvocation + ", afterInvocation=" + afterInvocation + '}';
+ }
+ }
+
+ /**
+ * Implementation of TestRule that records the order of callbacks invoked on
+ * it. Used by {@link RuleListTest}.
+ */
+ public static class SpyRule extends ExternalResource {
+
+ static SpyRuleBuilder builder() {
+ return new SpyRuleBuilder();
+ }
+
+ private final String name;
+ private final Invocations invocations;
+ private final Throwable beforeClassThrowable;
+ private final Throwable beforeThrowable;
+
+ SpyRule(String name, Invocations invocations) {
+ this.name = name;
+ this.invocations = invocations;
+ this.beforeClassThrowable = null;
+ this.beforeThrowable = null;
+ }
+
+ SpyRule(SpyRuleBuilder builder) {
+ this.name = builder.name;
+ this.invocations = builder.invocations;
+ this.beforeClassThrowable = builder.beforeClassThrowable;
+ this.beforeThrowable = builder.beforeThrowable;
+ }
+
+ Invocations invocations() {
+ return this.invocations;
+ }
+
+ void test() {
+ this.invocations.invokedTest();
+ }
+
+ @Override
+ protected void before() throws Throwable {
+ this.invocations.invokedBefore();
+ if (this.beforeThrowable != null) {
+ throw this.beforeThrowable;
+ }
+ }
+
+ @Override
+ protected void after() {
+ this.invocations.invokedAfter();
+ }
+
+ @Override
+ public String toString() {
+ return "SpyRule{" + "name='" + name + '\'' + '}';
+ }
+ }
+
+ /**
+ * Builder for more control of constructing an instance of {@link SpyRule}
+ */
+ public static class SpyRuleBuilder {
+
+ String name;
+ Invocations invocations;
+ Throwable beforeClassThrowable;
+ Throwable beforeThrowable;
+
+ SpyRuleBuilder withName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ SpyRuleBuilder withInvocations(Invocations invocations) {
+ this.invocations = invocations;
+ return this;
+ }
+
+ SpyRuleBuilder beforeClassThrows(Throwable throwable) {
+ this.beforeClassThrowable = throwable;
+ return this;
+ }
+
+ SpyRuleBuilder beforeThrows(Throwable throwable) {
+ this.beforeThrowable = throwable;
+ return this;
+ }
+
+ SpyRule build() {
+ return new SpyRule(this);
+ }
+ }
+}