-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoringTestRule.java
More file actions
41 lines (34 loc) · 1.03 KB
/
ScoringTestRule.java
File metadata and controls
41 lines (34 loc) · 1.03 KB
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
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
public class ScoringTestRule implements TestRule {
private int points = 0;
private int total = 0;
public int getPoints() {
return points;
}
public int getTotal() {
return total;
}
private void addPoints(int points) {
this.points += points;
}
private void addPointsToTotal(int points) {
this.total += points;
}
@Override
public Statement apply(final Statement baseStatement, final Description description) {
final WorthPoints annotation = description.getAnnotation(WorthPoints.class);
if (annotation == null) {
return baseStatement;
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
addPointsToTotal(annotation.points());
baseStatement.evaluate();
addPoints(annotation.points());
}
};
}
}