forked from junit-team/junit4
/
IgnoreUtil.java
58 lines (51 loc) · 1.59 KB
/
IgnoreUtil.java
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
package org.junit.internal;
import org.junit.Ignore;
import org.junit.RuntimeCondition;
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
/**
* Created by IntelliJ IDEA.
*
* @author jerome@coffeebreaks.org
* @since 2/11/11 2:18 PM
*/
public class IgnoreUtil {
public static boolean isIgnored(FrameworkMethod method) {
Ignore annotation = method.getAnnotation(Ignore.class);
return annotation != null && isTrue(annotation.ifTrue(), method);
}
private static boolean isTrue(Class<? extends RuntimeCondition>[] conditions, FrameworkMethod method) {
if (conditions == null || conditions.length == 0) {
return true;
}
for(Class<? extends RuntimeCondition> condition : conditions){
try{
if (! condition.newInstance().isTrue(method)) {
return false;
}
} catch(Exception e){
throw new RuntimeException(e);
}
}
return true;
}
public static boolean isIgnored(Description description) {
Ignore annotation = description.getAnnotation(Ignore.class);
return annotation != null && isTrue(annotation.ifTrue(), description);
}
private static boolean isTrue(Class<? extends RuntimeCondition>[] conditions, Description description) {
if (conditions == null || conditions.length == 0) {
return true;
}
for(Class<? extends RuntimeCondition> condition : conditions){
try{
if (! condition.newInstance().isTrue(description)) {
return false;
}
} catch(Exception e){
throw new RuntimeException(e);
}
}
return true;
}
}