summaryrefslogtreecommitdiffstats
path: root/junit4/src/test/java/org/junit/tests/running/classes/TestClassTest.java
blob: 7b738d9f40f1df0df337a90b25d91f3c682a6efe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package org.junit.tests.running.classes;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runners.model.TestClass;

public class TestClassTest {
	public static class TwoConstructors {
		public TwoConstructors() {
		}

		public TwoConstructors(int x) {
		}
	}

	@Test(expected= IllegalArgumentException.class)
	public void complainIfMultipleConstructors() {
		new TestClass(TwoConstructors.class);
	}

	public static class ManyMethods {
		@Test
		public void a() {
		}

		@Before
		public void b() {
		}

		@Ignore
		@Test
		public void c() {
		}

		@Ignore
		@After
		public void d() {
		}

		public void e() {
		}

		@BeforeClass
		public void f() {
		}

		public void g() {
		}

		@AfterClass
		public void h() {
		}

		@Test
		public void i() {
		}

		@Test
		public void j() {
		}
	}

	public static class SuperclassWithField {
		@Rule
		public TestRule x;
	}

	public static class SubclassWithField extends SuperclassWithField {
		@Rule
		public TestRule x;
	}

	@Test
	public void fieldsOnSubclassesShadowSuperclasses() {
		assertThat(new TestClass(SubclassWithField.class).getAnnotatedFields(
				Rule.class).size(), is(1));
	}

	public static class OuterClass {
		public class NonStaticInnerClass {
		}
	}

	@Test
	public void identifyNonStaticInnerClass() {
		assertThat(
				new TestClass(OuterClass.NonStaticInnerClass.class)
						.isANonStaticInnerClass(),
				is(true));
	}

	public static class OuterClass2 {
		public static class StaticInnerClass {
		}
	}

	@Test
	public void dontMarkStaticInnerClassAsNonStatic() {
		assertThat(
				new TestClass(OuterClass2.StaticInnerClass.class)
						.isANonStaticInnerClass(),
				is(false));
	}

	public static class SimpleClass {
	}

	@Test
	public void dontMarkNonInnerClassAsInnerClass() {
		assertThat(new TestClass(SimpleClass.class).isANonStaticInnerClass(),
				is(false));
	}
}