Permalink
Browse files

ClassRules example

Added ClassRule example from 4.9 Release Notes
  • Loading branch information...
1 parent e8f6fd9 commit 46528cdf8e8c18fd917f0cac6b603f8baeb424d4 @marcphilipp committed Oct 9, 2011
@@ -0,0 +1,11 @@
+package org.junit.rules.classrules;
+
+import org.junit.Test;
+
+public class A {
+
+ @Test
+ public void a() throws Exception {
+ System.out.println("a");
+ }
+}
@@ -0,0 +1,11 @@
+package org.junit.rules.classrules;
+
+import org.junit.Test;
+
+public class B {
+
+ @Test
+ public void b() throws Exception {
+ System.out.println("b");
+ }
+}
@@ -0,0 +1,11 @@
+package org.junit.rules.classrules;
+
+import org.junit.Test;
+
+public class C {
+
+ @Test
+ public void c() throws Exception {
+ System.out.println("c");
+ }
+}
@@ -0,0 +1,13 @@
+package org.junit.rules.classrules;
+
+public class Server {
+
+ public void connect() {
+ System.out.println("Connected");
+ }
+
+ public void disconnect() {
+ System.out.println("Disconnected");
+ }
+
+}
@@ -0,0 +1,27 @@
+package org.junit.rules.classrules;
+
+import org.junit.ClassRule;
+import org.junit.rules.ExternalResource;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({ A.class, B.class, C.class })
+public class UsesExternalResource {
+
+ public static Server myServer = new Server();
+
+ @ClassRule
+ public static ExternalResource connection = new ExternalResource() {
+ @Override
+ protected void before() throws Throwable {
+ myServer.connect();
+ };
+
+ @Override
+ protected void after() {
+ myServer.disconnect();
+ };
+ };
+}

0 comments on commit 46528cd

Please sign in to comment.