Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2010 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.callbackparams.junit4.version;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;

Author(s):
Henrik Kaipe
public abstract class CallbackRunListener extends RunListener {
//    private static final Pattern methodDisplayNameRgx =
//            Pattern.compile("^([^\\[\\(]++)(.*)\\(.++");
    private Map<String,StringnoargProxyMethods;
    private String currentRecordString = "";

    
Unfortunatelly the only Description factory-method that is available for all versions of JUnit-4.x is one that demand the test-class :(
    private Class<?> testClass;
    public void setCurrentRecordString(String currentRecordString) {
        this. = currentRecordString;
    }
    public void setNoargProxyMethods(Map<String,StringnoargProxyMethods) {
        this. = noargProxyMethods;
    }
    public void setTestClass(Class<?> testClass) {
        this. = testClass;
    }
    protected Description modify(Description d) {
        String displayName = d.getDisplayName();
        int classStart = displayName.lastIndexOf('(');
        if (classStart <= 0) {
            return d;
        } else {
            int methodNameEnd = Math.min(displayName.indexOf('['), classStart);
            if (methodNameEnd < 0) {
                methodNameEnd = classStart;
            }
            String testMethodName = displayName.substring(0, methodNameEnd);
            if (.containsKey(testMethodName)) {
                testMethodName = .get(testMethodName);
            }
            return Description.createTestDescription(testMethodName
                    + displayName.subSequence(methodNameEndclassStart)
                    + );
        }
        /*
         * The regex-based implemenation below was used until the above
         * indexOf-hell was introduced because of some significant
         * performance hits.
         * The test "org.callbackparams.junit4.TestBasicCombineCounting" (in
         * project "CallbackParams - JUnit4 Tests") demanded 15% more
         * execution time when the regex-based implementation was used.
         */
//        Matcher m = methodDisplayNameRgx.matcher(displayName);
//        if (m.matches()) {
//            return Description.createTestDescription(testClass,
//                    noargProxyMethods.get(m.group(1))
//                    + m.group(2) + currentRecordString);
//        } else {
//            return d;
//        }
    }
    protected Failure modify(Failure f) {
        return new Failure(modify(f.getDescription()), f.getException());
    }
New to GrepCode? Check out our FAQ X