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} and {@link UnitilsInvocationExceptionTest} tests.
25: *
26: * @author Tim Ducheyne
27: */
28: public class UnitilsJUnit3Test_TestClass1 extends UnitilsJUnit3 {
29:
30: /* Test listener that will record all invocations */
31: private static TracingTestListener tracingTestListener;
32:
33: /**
34: * Sets the tracing test listener that will record all invocations.
35: *
36: * @param testListener the listener
37: */
38: public static void setTracingTestListener(
39: TracingTestListener testListener) {
40: tracingTestListener = testListener;
41: }
42:
43: protected void setUp() throws Exception {
44: super .setUp();
45: addTestInvocation(TEST_SET_UP, null);
46: }
47:
48: protected void tearDown() throws Exception {
49: super .tearDown();
50: addTestInvocation(TEST_TEAR_DOWN, null);
51: }
52:
53: public void test1() {
54: addTestInvocation(TEST_METHOD, "test1");
55: }
56:
57: public void test2() {
58: addTestInvocation(TEST_METHOD, "test2");
59: }
60:
61: /**
62: * Records an invocation.
63: *
64: * @param invocation the invocation type, not null
65: * @param testMethodName the actual test name, null if not applicable
66: */
67: private void addTestInvocation(String invocation,
68: String testMethodName) {
69: if (tracingTestListener != null) {
70: tracingTestListener.addTestInvocation(invocation, this ,
71: testMethodName);
72: }
73: }
74:
75: /**
76: * Overridden to install the tracing test listener.
77: *
78: * @return the unitils instance, not null
79: */
80: @Override
81: protected Unitils getUnitils() {
82: if (tracingTestListener != null) {
83: return new Unitils() {
84:
85: @Override
86: public TestListener createTestListener() {
87: return tracingTestListener;
88: }
89: };
90: }
91: return super.getUnitils();
92: }
93: }
|