Skip to content

Commit 96083b1

Browse files
author
'1299310140'
committed
extension
1 parent 0a6ebbc commit 96083b1

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

students/1299310140/src/com/coderising/junit/AllTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22

33
public class AllTest {
44

5+
// public static Test suite(){
6+
// TestSuite suite = new TestSuite("All Test");
7+
// suite.addTestSuite(CalculatorTest.class);
8+
// suite.addTestSuite(CalculatorTest.class);
9+
// return suite;
10+
// }
11+
512
public static Test suite(){
613
TestSuite suite = new TestSuite("All Test");
7-
suite.addTestSuite(CalculatorTest.class);
8-
suite.addTestSuite(CalculatorTest.class);
9-
return suite;
14+
suite.addTest(CalculatorSuite.suite());
15+
// suite.addTestSuite(CalculatorTest.class);
16+
suite.addTest(new RepeatedTest(new TestSuite(CalculatorTest.class),3));
17+
return new OverallTestSetup(suite);
18+
}
19+
20+
static class OverallTestSetup extends TestSetUp{
21+
22+
public OverallTestSetup(Test test) {
23+
super(test);
24+
}
25+
26+
@Override
27+
public void setUp(){
28+
System.out.println("this is overall testsetup");
29+
}
30+
31+
@Override
32+
public void tearDown(){
33+
System.out.println("this is overall testteardown");
34+
}
1035
}
1136
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.coderising.junit;
2+
3+
public interface Protectable {
4+
public void protect() throws Throwable;
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.coderising.junit;
2+
3+
public class RepeatedTest extends TestDecorator {
4+
5+
private int fTimesRepeat;
6+
7+
public RepeatedTest(Test test,int repeat) {
8+
super(test);
9+
if(repeat < 0)
10+
throw new IllegalArgumentException("repeation count must be > 0");
11+
this.fTimesRepeat = repeat;
12+
}
13+
14+
public int countTestCases(){
15+
return super.countTestCases() * fTimesRepeat;
16+
}
17+
18+
public void run(TestResult testResult){
19+
for(int i = 0;i < fTimesRepeat;i++){
20+
super.run(testResult);
21+
}
22+
}
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.coderising.junit;
2+
3+
public class TestDecorator implements Test {
4+
5+
protected Test test;
6+
7+
public TestDecorator(Test test){
8+
this.test = test;
9+
}
10+
11+
@Override
12+
public void run(TestResult tr) {
13+
basicRun(tr);
14+
}
15+
16+
public void basicRun(TestResult tr) {
17+
this.test.run(tr);
18+
}
19+
20+
@Override
21+
public int countTestCases() {
22+
23+
return test.countTestCases();
24+
}
25+
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.coderising.junit;
2+
3+
public class TestSetUp extends TestDecorator {
4+
5+
public TestSetUp(Test test) {
6+
super(test);
7+
}
8+
9+
public void run(final TestResult testResult){
10+
Protectable p = new Protectable() {
11+
@Override
12+
public void protect() throws Throwable {
13+
setUp();
14+
basicRun(testResult);
15+
tearDown();
16+
}
17+
};
18+
19+
testResult.runProtected(this, p);
20+
}
21+
22+
protected void tearDown() {
23+
24+
}
25+
26+
protected void setUp() {
27+
28+
}
29+
30+
}

0 commit comments

Comments
 (0)