@@ -118,9 +118,6 @@ public static class CategoryFilter extends Filter {
118
118
private final boolean excludedAny ;
119
119
120
120
public static CategoryFilter include (boolean matchAny , Class <?>... categories ) {
121
- if (hasNull (categories )) {
122
- throw new NullPointerException ("has null category" );
123
- }
124
121
return new CategoryFilter (matchAny , categories , true , null );
125
122
}
126
123
@@ -133,9 +130,6 @@ public static CategoryFilter include(Class<?>... categories) {
133
130
}
134
131
135
132
public static CategoryFilter exclude (boolean matchAny , Class <?>... categories ) {
136
- if (hasNull (categories )) {
137
- throw new NullPointerException ("has null category" );
138
- }
139
133
return new CategoryFilter (true , null , matchAny , categories );
140
134
}
141
135
@@ -154,7 +148,10 @@ public static CategoryFilter categoryFilter(boolean matchAnyInclusions, Set<Clas
154
148
155
149
@ Deprecated
156
150
public CategoryFilter (Class <?> includedCategory , Class <?> excludedCategory ) {
157
- this (true , createSet (includedCategory ), true , createSet (excludedCategory ));
151
+ includedAny = true ;
152
+ excludedAny = true ;
153
+ included = nullableClassToSet (includedCategory );
154
+ excluded = nullableClassToSet (excludedCategory );
158
155
}
159
156
160
157
protected CategoryFilter (boolean matchAnyIncludes , Set <Class <?>> includes ,
@@ -305,16 +302,6 @@ private static Set<Class<?>> copyAndRefine(Set<Class<?>> classes) {
305
302
c .remove (null );
306
303
return c ;
307
304
}
308
-
309
- private static boolean hasNull (Class <?>... classes ) {
310
- if (classes == null ) return false ;
311
- for (Class <?> clazz : classes ) {
312
- if (clazz == null ) {
313
- return true ;
314
- }
315
- }
316
- return false ;
317
- }
318
305
}
319
306
320
307
public Categories (Class <?> klass , RunnerBuilder builder ) throws InitializationError {
@@ -360,12 +347,28 @@ private static boolean hasAssignableTo(Set<Class<?>> assigns, Class<?> to) {
360
347
return false ;
361
348
}
362
349
363
- private static Set <Class <?>> createSet (Class <?>... t ) {
350
+ private static Set <Class <?>> createSet (Class <?>[] t ) {
351
+ // Not throwing a NPE if t is null is a bad idea, but it's the behavior from JUnit 4.12
352
+ // for include(boolean, Class<?>...) and exclude(boolean, Class<?>...)
364
353
if (t == null || t .length == 0 ) {
365
354
return Collections .emptySet ();
366
- } else if (t .length == 1 ) {
367
- return Collections .<Class <?>>singleton (t [0 ]);
368
355
}
369
- return new HashSet <Class <?>>(Arrays .asList (t ));
356
+ for (Class <?> category : t ) {
357
+ if (category == null ) {
358
+ throw new NullPointerException ("has null category" );
359
+ }
360
+ }
361
+
362
+ return t .length == 1
363
+ ? Collections .<Class <?>>singleton (t [0 ])
364
+ : new HashSet <Class <?>>(Arrays .asList (t ));
365
+ }
366
+
367
+ private static Set <Class <?>> nullableClassToSet (Class <?> nullableClass ) {
368
+ // Not throwing a NPE if t is null is a bad idea, but it's the behavior from JUnit 4.11
369
+ // for CategoryFilter(Class<?> includedCategory, Class<?> excludedCategory)
370
+ return nullableClass == null
371
+ ? Collections .<Class <?>>emptySet ()
372
+ : Collections .<Class <?>>singleton (nullableClass );
370
373
}
371
374
}
0 commit comments