01: /*
02: * Copyright 2006-2007, Unitils.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.unitils;
17:
18: import static org.unitils.TracingTestListener.*;
19: import org.unitils.core.TestListener;
20: import org.unitils.core.Unitils;
21:
22: /**
23: * JUnit 3 test class containing 2 test methods. This test test-class is used in the
24: * {@link UnitilsInvocationTest} tests.
25: *
26: * @author Tim Ducheyne
27: * @author Filip Neven
28: */
29: public class UnitilsJUnit3Test_TestClass2 extends UnitilsJUnit3 {
30:
31: /* Test listener that will record all invocations */
32: private static TracingTestListener tracingTestListener;
33:
34: /**
35: * Sets the tracing test listener that will record all invocations.
36: *
37: * @param testListener the listener
38: */
39: public static void setTracingTestListener(
40: TracingTestListener testListener) {
41: tracingTestListener = testListener;
42: }
43:
44: protected void setUp() throws Exception {
45: super .setUp();
46: addTestInvocation(TEST_SET_UP, null);
47: }
48:
49: protected void tearDown() throws Exception {
50: super .tearDown();
51: addTestInvocation(TEST_TEAR_DOWN, null);
52: }
53:
54: public void test1() {
55: addTestInvocation(TEST_METHOD, "test1");
56: }
57:
58: public void test2() {
59: addTestInvocation(TEST_METHOD, "test2");
60: }
61:
62: /**
63: * Records an invocation.
64: *
65: * @param invocation the invocation type, not null
66: * @param testMethodName the actual test name, null if not applicable
67: */
68: private void addTestInvocation(String invocation,
69: String testMethodName) {
70: if (tracingTestListener != null) {
71: tracingTestListener.addTestInvocation(invocation, this ,
72: testMethodName);
73: }
74: }
75:
76: /**
77: * Overridden to install the tracing test listener.
78: *
79: * @return the unitils instance, not null
80: */
81: @Override
82: protected Unitils getUnitils() {
83: if (tracingTestListener != null) {
84: return new Unitils() {
85:
86: @Override
87: public TestListener createTestListener() {
88: return tracingTestListener;
89: }
90: };
91: }
92: return super.getUnitils();
93: }
94: }
|