Permalink
Browse files

Add test for global Timeout now taking a long and TimeUnit in the con…

…structor
  • Loading branch information...
1 parent 2889e27 commit 3637c35d8bf0ff75169747f00836eba44d645ae0 @davidhart82 committed Aug 23, 2012
Showing with 34 additions and 9 deletions.
  1. +34 −9 src/test/java/org/junit/tests/experimental/rules/TimeoutRuleTest.java
@@ -3,7 +3,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
-import org.junit.Ignore;
+
+import java.util.concurrent.TimeUnit;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
@@ -12,10 +14,10 @@
import org.junit.runner.Result;
public class TimeoutRuleTest {
- public static class HasGlobalTimeout {
+ public static class HasGlobalLongTimeout {
public static String log;
- @Rule public TestRule globalTimeout = new Timeout(20);
+ @Rule public TestRule globalTimeout = new Timeout(200);
@Test public void testInfiniteLoop1() {
log+= "ran1";
@@ -28,12 +30,35 @@
}
}
- @Ignore("For gump, for now")
- @Test(timeout=100) public void globalTimeoutAvoidsInfiniteLoop() {
- HasGlobalTimeout.log = "";
- Result result= JUnitCore.runClasses(HasGlobalTimeout.class);
+ public static class HasGlobalTimeUnitTimeout {
+ public static String log;
+
+ @Rule public TestRule globalTimeout = new Timeout(200, TimeUnit.MILLISECONDS);
+
+ @Test public void testInfiniteLoop1() {
+ log+= "ran1";
+ for(;;) {}
+ }
+
+ @Test public void testInfiniteLoop2() {
+ log+= "ran2";
+ for(;;) {}
+ }
+ }
+
+ @Test(timeout=1000) public void globalLongTimeoutAvoidsInfiniteLoop() {
+ HasGlobalLongTimeout.log = "";
+ Result result= JUnitCore.runClasses(HasGlobalLongTimeout.class);
+ assertEquals(2, result.getFailureCount());
+ assertThat(HasGlobalLongTimeout.log, containsString("ran1"));
+ assertThat(HasGlobalLongTimeout.log, containsString("ran2"));
+ }
+
+ @Test(timeout=1000) public void globalTimeUnitTimeoutAvoidsInfiniteLoop() {
+ HasGlobalLongTimeout.log = "";
+ Result result= JUnitCore.runClasses(HasGlobalTimeUnitTimeout.class);
assertEquals(2, result.getFailureCount());
- assertThat(HasGlobalTimeout.log, containsString("ran1"));
- assertThat(HasGlobalTimeout.log, containsString("ran2"));
+ assertThat(HasGlobalTimeUnitTimeout.log, containsString("ran1"));
+ assertThat(HasGlobalTimeUnitTimeout.log, containsString("ran2"));
}
}

0 comments on commit 3637c35

Please sign in to comment.