001    /*
002     * $Id: JUnitHelper.java,v 1.3 2011/07/09 21:43:22 oboehm Exp $
003     *
004     * Copyright (c) 2010 by Oliver Boehm
005     *
006     * Licensed under the Apache License, Version 2.0 (the "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *   http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     *
018     * (c)reated 29.03.2010 by oliver (ob@oasd.de)
019     */
020    
021    package patterntesting.runtime.junit.internal;
022    
023    import java.lang.reflect.Method;
024    
025    import org.junit.runners.model.FrameworkMethod;
026    import org.slf4j.*;
027    
028    import patterntesting.annotation.check.runtime.MayReturnNull;
029    
030    /**
031     * This is a helper class which contains some static helper methods for
032     * JUnit.
033     *
034     * @author oliver
035     * @since 1.0 (29.03.2010)
036     */
037    public final class JUnitHelper {
038    
039        private static final Logger log = LoggerFactory.getLogger(JUnitHelper.class);
040    
041        /** No need to instantiate it (utility class). */
042        private JUnitHelper() {}
043    
044        /**
045         * Returns the given name as FrameworkMethod.
046         * This method is package visible because it use also by JUnit3Executor.
047         *
048         * @param testClass the JUnit3 test class
049         * @param name e.g. "setUp"
050         * @return null if name was not found
051         */
052        @MayReturnNull
053        public static FrameworkMethod getFrameworkMethod(final Class<?> testClass, final String name) {
054            try {
055                Method method = testClass.getDeclaredMethod(name);
056                return new FrameworkMethod(method);
057            } catch (NoSuchMethodException e) {
058                log.debug("{}", e);
059                return null;
060            }
061        }
062    
063    }
064