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 org.junit.*;
19: import static org.unitils.TracingTestListener.*;
20:
21: /**
22: * JUnit 4 test class containing 2 test methods. This test test-class is used in the {@link UnitilsInvocationTest} tests.
23: *
24: * @author Tim Ducheyne
25: */
26: public class UnitilsJUnit4Test_TestClass2 extends UnitilsJUnit4 {
27:
28: /* Test listener that will record all invocations */
29: private static TracingTestListener tracingTestListener;
30:
31: /**
32: * Sets the tracing test listener that will record all invocations.
33: *
34: * @param testListener the listener
35: */
36: public static void setTracingTestListener(
37: TracingTestListener testListener) {
38: tracingTestListener = testListener;
39: }
40:
41: @BeforeClass
42: public static void beforeClass() {
43: addTestInvocation(TEST_BEFORE_CLASS,
44: UnitilsJUnit4Test_TestClass2.class, null);
45: }
46:
47: @AfterClass
48: public static void afterClass() {
49: addTestInvocation(TEST_AFTER_CLASS,
50: UnitilsJUnit4Test_TestClass2.class, null);
51: }
52:
53: @Before
54: public void setUp() {
55: addTestInvocation(TEST_SET_UP, this , null);
56: }
57:
58: @After
59: public void tearDown() {
60: addTestInvocation(TEST_TEAR_DOWN, this , null);
61: }
62:
63: @Test
64: public void test1() {
65: addTestInvocation(TEST_METHOD, this , "test1");
66: }
67:
68: @Test
69: public void test2() {
70: addTestInvocation(TEST_METHOD, this , "test2");
71: }
72:
73: /**
74: * Records an invocation.
75: *
76: * @param invocation the invocation type, not null
77: * @param test the test instance or class, not null
78: * @param testMethodName the actual test name, null if not applicable
79: */
80: private static void addTestInvocation(String invocation,
81: Object test, String testMethodName) {
82: if (tracingTestListener != null) {
83: tracingTestListener.addTestInvocation(invocation, test,
84: testMethodName);
85: }
86: }
87: }
|