summaryrefslogtreecommitdiffstats
path: root/junit4/src/test/java/junit/tests/framework/TestImplementorTest.java
blob: a5f0962ebc0c06edddb1e3de959cae718e1aba57 (plain)
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
package junit.tests.framework;

import junit.framework.Protectable;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;

/**
 * Test an implementor of junit.framework.Test other than TestCase or TestSuite
 */
public class TestImplementorTest extends TestCase {
	public static class DoubleTestCase implements Test {
		private TestCase fTestCase;
		
		public DoubleTestCase(TestCase testCase) {
			fTestCase= testCase;
		}
		
		public int countTestCases() {
			return 2;
		}
		
		public void run(TestResult result) {
			result.startTest(this);
			Protectable p= new Protectable() {
				public void protect() throws Throwable {
					fTestCase.runBare();
					fTestCase.runBare();
				}
			};
			result.runProtected(this, p);
			result.endTest(this);
		}
	}
	
	private DoubleTestCase fTest;
	
	public TestImplementorTest() {
		TestCase testCase= new TestCase() {
			@Override
			public void runTest() {
			}
		};
		fTest= new DoubleTestCase(testCase);
	}
	
	public void testSuccessfulRun() {
		TestResult result= new TestResult();
		fTest.run(result);
		assertEquals(fTest.countTestCases(), result.runCount());
		assertEquals(0, result.errorCount());
		assertEquals(0, result.failureCount());
	}
}