コード例 #1
0
 private Object[] invokeParamsProvidingMethod(Class<?> testClass, Method provideMethod) {
   try {
     Object testObject = testClass.newInstance();
     provideMethod.setAccessible(true);
     Object[] params = (Object[]) provideMethod.invoke(testObject);
     return processParamsIfSingle(params);
   } catch (Exception e) {
     throw new RuntimeException(
         "Could not invoke method: "
             + provideMethod.getName()
             + " defined in class "
             + testClass
             + " so no params were used.",
         e);
   }
 }
コード例 #2
0
 private ArrayList<Object> gatherParamsFromAllMethodsFrom(Class<?> sourceClass) {
   ArrayList<Object> result = new ArrayList<Object>();
   Method[] methods = sourceClass.getDeclaredMethods();
   for (Method method : methods) {
     if (method.getName().startsWith("provide")) {
       if (!Modifier.isStatic(method.getModifiers()))
         throw new RuntimeException(
             "Parameters source method "
                 + method.getName()
                 + " is not declared as static. Modify it to a static method.");
       try {
         result.addAll(Arrays.asList(processParamsIfSingle((Object[]) method.invoke(null))));
       } catch (Exception e) {
         throw new RuntimeException(
             "Cannot invoke parameters source method: " + method.getName(), e);
       }
     }
   }
   return result;
 }