1 package org.junit.tests.validation;
2
3 import static org.junit.Assert.assertEquals;
4
5 import org.junit.BeforeClass;
6 import org.junit.Test;
7 import org.junit.runner.JUnitCore;
8 import org.junit.runner.Request;
9 import org.junit.runner.Result;
10
11 public class ValidationTest {
12 public static class WrongBeforeClass {
13 @BeforeClass
14 protected int a() {
15 return 0;
16 }
17 }
18
19 @Test
20 public void initializationErrorIsOnCorrectClass() {
21 assertEquals(WrongBeforeClass.class.getName(),
22 Request.aClass(WrongBeforeClass.class).getRunner().getDescription().getDisplayName());
23 }
24
25 public static class NonStaticBeforeClass {
26 @BeforeClass
27 public void before() {
28 }
29
30 @Test
31 public void hereBecauseEveryTestClassNeedsATest() {
32 }
33 }
34
35 @Test
36 public void nonStaticBeforeClass() {
37 Result result = JUnitCore.runClasses(NonStaticBeforeClass.class);
38 assertEquals("Method before() should be static", result.getFailures().get(0).getMessage());
39 }
40 }