Browse files

RuleChain-Beispiel

  • Loading branch information...
1 parent 46528cd commit 5f3e4cbd472c7010df0e3dea5d85a1af464cf826 @marcphilipp committed Oct 10, 2011
View
25 junit-rules/src/test/java/org/junit/rules/order/LoggingRule.java
@@ -0,0 +1,25 @@
+package org.junit.rules.order;
+
+import static java.lang.System.out;
+
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+public class LoggingRule extends TestWatcher {
+
+ private final String value;
+
+ public LoggingRule(String value) {
+ this.value = value;
+ }
+
+ @Override
+ protected void starting(Description description) {
+ out.println("starting " + value);
+ }
+
+ @Override
+ protected void finished(Description description) {
+ out.println("finished " + value);
+ }
+}
View
51 junit-rules/src/test/java/org/junit/rules/order/Order.java
@@ -0,0 +1,51 @@
+package org.junit.rules.order;
+
+import static java.lang.System.out;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+
+public class Order {
+
+ @ClassRule
+ public static TestRule classRule = new LoggingRule("class rule");
+
+ @Rule
+ public TestRule methodRule = new LoggingRule("method rule");
+
+ @BeforeClass
+ public static void beforeClass() {
+ out.println("beforeClass()");
+ }
+
+ @Before
+ public void before() {
+ out.println("before()");
+ }
+
+ @Test
+ public void test1() {
+ out.println("test1()");
+ }
+
+ @Test
+ public void test2() {
+ out.println("test2()");
+ }
+
+ @After
+ public void after() {
+ out.println("after()");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ out.println("afterClass()");
+ }
+}
View
17 junit-rules/src/test/java/org/junit/rules/order/UseRuleChain.java
@@ -0,0 +1,17 @@
+package org.junit.rules.order;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+
+public class UseRuleChain {
+ @Rule
+ public TestRule chain = RuleChain.outerRule(new LoggingRule("outer rule"))
+ .around(new LoggingRule("middle rule"))//
+ .around(new LoggingRule("inner rule"));
+
+ @Test
+ public void test() {
+ }
+}

0 comments on commit 5f3e4cb

Please sign in to comment.