View Javadoc
1   package org.junit.tests.deprecated;
2   
3   import static org.hamcrest.CoreMatchers.is;
4   import static org.junit.Assert.assertThat;
5   import static org.junit.Assert.fail;
6   
7   import org.junit.Test;
8   import org.junit.internal.runners.JUnit4ClassRunner;
9   import org.junit.runner.JUnitCore;
10  import org.junit.runner.Result;
11  import org.junit.runner.RunWith;
12  
13  /**
14   * @deprecated This is a simple smoke test to make sure the old JUnit4ClassRunner basically works.
15   *             Delete this test when JUnit4ClassRunner goes to the Great Heap In The Sky.
16   */
17  @Deprecated
18  public class JUnit4ClassRunnerTest {
19  
20      @SuppressWarnings("deprecation")
21      @RunWith(JUnit4ClassRunner.class)
22      public static class Example {
23          @Test
24          public void success() {
25          }
26  
27          @Test
28          public void failure() {
29              fail();
30          }
31      }
32  
33      @Test
34      public void runWithOldJUnit4ClassRunner() {
35          Result result = JUnitCore.runClasses(Example.class);
36          assertThat(result.getRunCount(), is(2));
37          assertThat(result.getFailureCount(), is(1));
38      }
39  
40      @SuppressWarnings("deprecation")
41      @RunWith(JUnit4ClassRunner.class)
42      public static class UnconstructableExample {
43          public UnconstructableExample() {
44              throw new UnsupportedOperationException();
45          }
46  
47          @Test
48          public void success() {
49          }
50  
51          @Test
52          public void failure() {
53              fail();
54          }
55      }
56  
57  
58      @Test
59      public void runWithOldJUnit4ClassRunnerAndBadConstructor() {
60          Result result = JUnitCore.runClasses(UnconstructableExample.class);
61          assertThat(result.getRunCount(), is(2));
62          assertThat(result.getFailureCount(), is(2));
63      }
64  }