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