zoukankan      html  css  js  c++  java
  • 给Fitnesse添加调用多参数fixture的调用方法

    修改文件:fitnesse.slim.fixtureInteraction.DefaultInteraction.java

    修改如下三处内容:

    (注意只支持仅含有一个参数,且该参数是多参数的fixture)

     1 protected Method findMatchingMethod(String methodName, Class<?> k, int nArgs) {
     2         Method[] methods = k.getMethods();
     3         if(methods == null) {
     4             methods = k.getMethods();
     5         }
     6 
     7         for (Method method : methods) {
     8             boolean hasMatchingName = method.getName().equals(methodName);
     9             if(hasMatchingName && method.isVarArgs()){
    10                 return method;
    11             }
    12             boolean hasMatchingArguments = method.getParameterTypes().length == nArgs;
    13             if (hasMatchingName && hasMatchingArguments) {
    14                 return method;
    15             }
    16         }
    17         return null;
    18     }
    1 protected Object[] convertArgs(Method method, Object[] args) {
    2         Type[] argumentParameterTypes=null;
    3         if(method.isVarArgs()){
    4             return args;        
    5         }else{
    6             argumentParameterTypes = method.getGenericParameterTypes();
    7         }    
    8         return ConverterSupport.convertArgs(args, argumentParameterTypes);
    9     }
     1 public Object methodInvoke(Method method, Object instance, Object... convertedArgs) throws Throwable {
     2         try {
     3             if(method.isVarArgs()){
     4                 String[] s = new String[convertedArgs.length];
     5                 int i =0;
     6                 for(Object arg:convertedArgs){
     7                     s[i]=arg.toString();
     8                     i++;
     9                 }
    10                 return method.invoke(instance, (Object)s);
    11             }else{
    12                 return method.invoke(instance, convertedArgs);
    13             }
    14             
    15         } catch (InvocationTargetException e) {
    16             if(e.getCause() != null){
    17                 throw e.getCause();
    18             }else{
    19                 throw e.getTargetException();
    20             }
    21         }
    22     }

     使用例子:

  • 相关阅读:
    来一个炫酷的导航条
    jQuery实现瀑布流
    js计时事件
    js浏览器对象的属性和方法
    js对象(一)
    CSS3常用选择器(三)
    软工实践个人总结
    第05组 每周小结 (3/3)
    第05组 每周小结 (2/3)
    第05组 每周小结 (1/3)
  • 原文地址:https://www.cnblogs.com/moonpool/p/6514347.html
Copyright © 2011-2022 走看看