Home | History | Annotate | Download | only in junit
      1 package org.testng.junit;
      2 
      3 import java.lang.reflect.Method;
      4 import org.junit.runner.Description;
      5 import org.testng.internal.Utils;
      6 
      7 /**
      8  *
      9  * @author lukas
     10  */
     11 public class JUnit4TestMethod extends JUnitTestMethod {
     12 
     13     public JUnit4TestMethod(JUnitTestClass owner, Description desc) {
     14         super(owner, desc.getMethodName(), getMethod(desc), desc);
     15     }
     16 
     17     @Override
     18     public Object[] getInstances() {
     19         return new Object[0];
     20     }
     21 
     22     private static Method getMethod(Description desc) {
     23         Class<?> c = desc.getTestClass();
     24         String method = desc.getMethodName();
     25         // remove [index] from method name in case of parameterized test
     26         int idx = method.indexOf('[');
     27         if (idx != -1) {
     28             method = method.substring(0, idx);
     29         }
     30         try {
     31             return c.getMethod(method);
     32         } catch (Throwable t) {
     33             Utils.log("JUnit4TestMethod", 2,
     34                     "Method '" + method + "' not found in class '" + c.getName() + "': " + t.getMessage());
     35             return null;
     36         }
     37     }
     38 }
     39