01: /*
02: * Copyright 2007 the original author or authors.
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:
17: package org.springunit.framework.junit4;
18:
19: import org.junit.runner.Description;
20: import org.junit.runner.notification.RunListener;
21:
22: /**
23: * Obtains the name of the currently running test from the TestRunner.<br/>
24: * This implementation follows the example given by Gabriel Cooper at
25: * http://tech.groups.yahoo.com/group/junit/message/18728.<br/>
26: *
27: * @author <a href="mailto:ted@velkoff.com">Ted Velkoff</a>
28: *
29: */
30: public class NameListener extends RunListener {
31:
32: public void testStarted(Description description) throws Exception {
33: NameRunner.setTestName(description.isTest() ? description
34: .getDisplayName() : null);
35: }
36:
37: public void testFinished(Description description) throws Exception {
38: if (NameRunner.getTestName() != null) {
39: if (NameRunner.getTestName().equals(
40: description.getDisplayName())) {
41: NameRunner.setTestName(null);
42: } else {
43: throw new RuntimeException("Test name does not match");
44: }
45: }
46: }
47:
48: }
|