View Javadoc
1   package org.junit.tests.running.classes;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import java.util.List;
6   
7   import org.junit.Test;
8   import org.junit.runners.BlockJUnit4ClassRunner;
9   import org.junit.runners.model.InitializationError;
10  
11  public class BlockJUnit4ClassRunnerTest {
12      public static class OuterClass {
13          public class Enclosed {
14              @Test
15              public void test() {
16              }
17          }
18      }
19  
20      @Test
21      public void detectNonStaticEnclosedClass() throws Exception {
22          try {
23              new BlockJUnit4ClassRunner(OuterClass.Enclosed.class);
24          } catch (InitializationError e) {
25              List<Throwable> causes = e.getCauses();
26              assertEquals("Wrong number of causes.", 1, causes.size());
27              assertEquals(
28                      "Wrong exception.",
29                      "The inner class org.junit.tests.running.classes.BlockJUnit4ClassRunnerTest$OuterClass$Enclosed is not static.",
30                      causes.get(0).getMessage());
31          }
32      }
33  }