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     }

     使用例子:

  • 相关阅读:
    常见HTTP状态(304,)
    面试错题集
    从零构建以太坊(Ethereum)智能合约到项目实战——学习笔记1
    windows 以太坊开发框架Truffle环境搭建
    Ollydbg使用问题汇总
    网络攻防实战技术之——缓冲区溢出篇
    如何批量删除.svn文件
    树莓派安装nextcloud、Seafile
    汇编语言从入门到精通-5微机CPU的指令系统2
    kali安装vm tools正确操作
  • 原文地址:https://www.cnblogs.com/moonpool/p/6514347.html
Copyright © 2011-2022 走看看