2
2
3
3
import static org .hamcrest .CoreMatchers .allOf ;
4
4
import static org .hamcrest .CoreMatchers .is ;
5
+ import static org .junit .Assert .assertEquals ;
6
+ import static org .junit .Assert .assertNotNull ;
5
7
import static org .junit .Assert .assertThat ;
6
8
import static org .junit .experimental .results .PrintableResult .testResult ;
7
9
import static org .junit .experimental .results .ResultMatchers .failureCountIs ;
8
10
import static org .junit .experimental .results .ResultMatchers .hasFailureContaining ;
9
11
import static org .junit .experimental .results .ResultMatchers .hasSingleFailureContaining ;
10
-
11
12
import org .hamcrest .CoreMatchers ;
12
13
import org .junit .Test ;
13
14
import org .junit .experimental .results .PrintableResult ;
14
15
import org .junit .experimental .theories .DataPoint ;
16
+ import org .junit .experimental .theories .DataPoints ;
15
17
import org .junit .experimental .theories .Theories ;
16
18
import org .junit .experimental .theories .Theory ;
17
19
import org .junit .runner .RunWith ;
18
20
import org .junit .runners .model .TestClass ;
19
21
20
22
public class UnsuccessfulWithDataPointFields {
21
23
@ RunWith (Theories .class )
22
- public static class HasATheory {
24
+ public static class HasAFailingTheory {
23
25
@ DataPoint
24
26
public static int ONE = 1 ;
25
27
@@ -31,19 +33,19 @@ public void everythingIsZero(int x) {
31
33
32
34
@ Test
33
35
public void theoryClassMethodsShowUp () throws Exception {
34
- assertThat (new Theories (HasATheory .class ).getDescription ()
36
+ assertThat (new Theories (HasAFailingTheory .class ).getDescription ()
35
37
.getChildren ().size (), is (1 ));
36
38
}
37
39
38
40
@ Test
39
41
public void theoryAnnotationsAreRetained () throws Exception {
40
- assertThat (new TestClass (HasATheory .class ).getAnnotatedMethods (
42
+ assertThat (new TestClass (HasAFailingTheory .class ).getAnnotatedMethods (
41
43
Theory .class ).size (), is (1 ));
42
44
}
43
45
44
46
@ Test
45
47
public void canRunTheories () throws Exception {
46
- assertThat (testResult (HasATheory .class ),
48
+ assertThat (testResult (HasAFailingTheory .class ),
47
49
hasSingleFailureContaining ("Expected" ));
48
50
}
49
51
@@ -83,75 +85,168 @@ public void nullsUsedUnlessProhibited() throws Exception {
83
85
assertThat (testResult (NullsOK .class ),
84
86
hasSingleFailureContaining ("null" ));
85
87
}
86
-
88
+
87
89
@ RunWith (Theories .class )
88
- public static class DataPointsMustBeStatic {
90
+ public static class TheoriesMustBePublic {
89
91
@ DataPoint
90
- public int THREE = 3 ;
92
+ public static int THREE = 3 ;
91
93
92
- @ DataPoint
93
- public int FOUR = 4 ;
94
+ @ Theory
95
+ void numbers (int x ) {
96
+
97
+ }
98
+ }
99
+
100
+ @ Test
101
+ public void theoriesMustBePublic () {
102
+ assertThat (
103
+ testResult (TheoriesMustBePublic .class ),
104
+ hasSingleFailureContaining ("public" ));
105
+ }
94
106
107
+ @ RunWith (Theories .class )
108
+ public static class DataPointFieldsMustBeStatic {
109
+ @ DataPoint
110
+ public int THREE = 3 ;
111
+
112
+ @ DataPoints
113
+ public int [] FOURS = new int [] { 4 };
114
+
95
115
@ Theory
96
116
public void numbers (int x ) {
97
117
98
118
}
99
119
}
100
120
101
121
@ Test
102
- public void dataPointsMustBeStatic () {
122
+ public void dataPointFieldsMustBeStatic () {
103
123
assertThat (
104
- testResult (DataPointsMustBeStatic .class ),
124
+ testResult (DataPointFieldsMustBeStatic .class ),
105
125
CoreMatchers .<PrintableResult >both (failureCountIs (2 ))
106
126
.and (
107
127
hasFailureContaining ("DataPoint field THREE must be static" ))
108
128
.and (
109
- hasFailureContaining ("DataPoint field FOUR must be static" )));
129
+ hasFailureContaining ("DataPoint field FOURS must be static" )));
110
130
}
111
-
131
+
112
132
@ RunWith (Theories .class )
113
- public static class TheoriesMustBePublic {
133
+ public static class DataPointMethodsMustBeStatic {
114
134
@ DataPoint
115
- public static int THREE = 3 ;
135
+ public int singleDataPointMethod () {
136
+ return 1 ;
137
+ }
138
+
139
+ @ DataPoints
140
+ public int [] dataPointArrayMethod () {
141
+ return new int [] { 1 , 2 , 3 };
142
+ }
116
143
117
144
@ Theory
118
- void numbers (int x ) {
119
-
145
+ public void numbers (int x ) {
146
+
120
147
}
121
148
}
122
-
149
+
123
150
@ Test
124
- public void theoriesMustBePublic () {
151
+ public void dataPointMethodsMustBeStatic () {
125
152
assertThat (
126
- testResult (TheoriesMustBePublic .class ),
127
- hasSingleFailureContaining ("public" ));
153
+ testResult (DataPointMethodsMustBeStatic .class ),
154
+ CoreMatchers .<PrintableResult >both (failureCountIs (2 ))
155
+ .and (
156
+ hasFailureContaining ("DataPoint method singleDataPointMethod must be static" ))
157
+ .and (
158
+ hasFailureContaining ("DataPoint method dataPointArrayMethod must be static" )));
128
159
}
129
160
130
161
@ RunWith (Theories .class )
131
- public static class DataPointsMustBePublic {
162
+ public static class DataPointFieldsMustBePublic {
132
163
@ DataPoint
133
164
static int THREE = 3 ;
165
+
166
+ @ DataPoints
167
+ static int [] THREES = new int [] { 3 };
134
168
135
169
@ DataPoint
136
170
protected static int FOUR = 4 ;
171
+
172
+ @ DataPoints
173
+ protected static int [] FOURS = new int [] { 4 };
137
174
138
- @ SuppressWarnings ("unused" )
139
175
@ DataPoint
140
176
private static int FIVE = 5 ;
177
+
178
+ @ DataPoints
179
+ private static int [] FIVES = new int [] { 5 };
141
180
142
181
@ Theory
143
182
public void numbers (int x ) {
144
-
183
+
145
184
}
146
185
}
147
186
148
187
@ Test
149
- public void dataPointsMustBePublic () {
150
- assertThat (
151
- testResult (DataPointsMustBePublic .class ),
152
- allOf (failureCountIs (3 ),
153
- hasFailureContaining ("DataPoint field THREE must be public" ),
154
- hasFailureContaining ("DataPoint field FOUR must be public" ),
155
- hasFailureContaining ("DataPoint field FIVE must be public" )));
188
+ public void dataPointFieldsMustBePublic () {
189
+ PrintableResult result = testResult (DataPointFieldsMustBePublic .class );
190
+ assertEquals (6 , result .failureCount ());
191
+
192
+ assertThat (result ,
193
+ allOf (hasFailureContaining ("DataPoint field THREE must be public" ),
194
+ hasFailureContaining ("DataPoint field THREES must be public" ),
195
+ hasFailureContaining ("DataPoint field FOUR must be public" ),
196
+ hasFailureContaining ("DataPoint field FOURS must be public" ),
197
+ hasFailureContaining ("DataPoint field FIVE must be public" ),
198
+ hasFailureContaining ("DataPoint field FIVES must be public" )));
199
+ }
200
+
201
+ @ RunWith (Theories .class )
202
+ public static class DataPointMethodsMustBePublic {
203
+ @ DataPoint
204
+ static int three () {
205
+ return 3 ;
206
+ }
207
+
208
+ @ DataPoints
209
+ static int [] threes () {
210
+ return new int [] { 3 };
211
+ }
212
+
213
+ @ DataPoint
214
+ protected static int four () {
215
+ return 4 ;
216
+ }
217
+
218
+ @ DataPoints
219
+ protected static int [] fours () {
220
+ return new int [] { 4 };
221
+ }
222
+
223
+ @ DataPoint
224
+ private static int five () {
225
+ return 5 ;
226
+ }
227
+
228
+ @ DataPoints
229
+ private static int [] fives () {
230
+ return new int [] { 5 };
231
+ }
232
+
233
+ @ Theory
234
+ public void numbers (int x ) {
235
+
236
+ }
237
+ }
238
+
239
+ @ Test
240
+ public void dataPointMethodsMustBePublic () {
241
+ PrintableResult result = testResult (DataPointMethodsMustBePublic .class );
242
+ assertEquals (6 , result .failureCount ());
243
+
244
+ assertThat (result ,
245
+ allOf (hasFailureContaining ("DataPoint method three must be public" ),
246
+ hasFailureContaining ("DataPoint method threes must be public" ),
247
+ hasFailureContaining ("DataPoint method four must be public" ),
248
+ hasFailureContaining ("DataPoint method fours must be public" ),
249
+ hasFailureContaining ("DataPoint method five must be public" ),
250
+ hasFailureContaining ("DataPoint method fives must be public" )));
156
251
}
157
252
}
0 commit comments