/apache-log4j-1.2.17/tests/src/java/org/apache/log4j/util/EnhancedJunitTestRunnerFilter.java
Java | 66 lines | 35 code | 9 blank | 22 comment | 8 complexity | 4ff1258d1e46d62bec59079967afa56b MD5 | raw file
Possible License(s): Apache-2.0
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package org.apache.log4j.util;
19
20import org.apache.oro.text.perl.Perl5Util;
21
22
23public class EnhancedJunitTestRunnerFilter implements Filter {
24 private Perl5Util util = new Perl5Util();
25
26 private static final String[] PATTERNS = {
27 "at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
28 "at org.apache.tools.ant",
29 "at junit.textui.TestRunner",
30 "at com.intellij.rt.execution.junit",
31 "at java.lang.reflect.Method.invoke",
32 "at org.apache.maven.",
33 "at org.codehaus.",
34 "at org.junit.internal.runners.",
35 "at junit.framework.JUnit4TestAdapter"
36 };
37
38 public EnhancedJunitTestRunnerFilter() {
39 }
40
41 /**
42 * Filter out stack trace lines coming from the various JUnit TestRunners.
43 */
44 public String filter(String in) {
45 if (in == null) {
46 return null;
47 }
48
49 //
50 // restore the one instance of Method.invoke that we actually want
51 //
52 if (in.indexOf("at junit.framework.TestCase.runTest") != -1) {
53 return "\tat java.lang.reflect.Method.invoke(X)\n\t" + in.trim();
54 }
55
56 for (int i = 0; i < PATTERNS.length; i++) {
57 if(in.indexOf(PATTERNS[i]) != -1) {
58 return null;
59 }
60 }
61 if (util.match("/\\sat /", in)) {
62 return "\t" + in.trim();
63 }
64 return in;
65 }
66}