1package junit.extensions;
2
3import junit.framework.Test;
4import junit.framework.TestResult;
5
6/**
7 * A Decorator that runs a test repeatedly.
8 */
9public class RepeatedTest extends TestDecorator {
10    private int fTimesRepeat;
11
12    public RepeatedTest(Test test, int repeat) {
13        super(test);
14        if (repeat < 0) {
15            throw new IllegalArgumentException("Repetition count must be >= 0");
16        }
17        fTimesRepeat = repeat;
18    }
19
20    @Override
21    public int countTestCases() {
22        return super.countTestCases() * fTimesRepeat;
23    }
24
25    @Override
26    public void run(TestResult result) {
27        for (int i = 0; i < fTimesRepeat; i++) {
28            if (result.shouldStop()) {
29                break;
30            }
31            super.run(result);
32        }
33    }
34
35    @Override
36    public String toString() {
37        return super.toString() + "(repeated)";
38    }
39}