虽然easymock中提供了大量的方法来进行参数匹配,但是对于一些特殊场合比如参数是复杂对象而又不能简单的通过equals()方法来比较,这些现有的参数匹配器就无能为力了。easymock为此提供了IArgumentMatcher 接口来让我们实现自定义的参数匹配器。

    我们还是用例子来说话:

要测试的接口

 

package MockTest;

public interface Service {
    void execute(Request request, MData[] mdata, int mode);
}

 

参数类型定义

package MockTest;

public class Request {
    private boolean condition;

    private String  value1;

    private String  value2;
    
    public boolean isCondition() {
        return condition;
    }

    public String getValue1() {
        return value1;
    }

    public String getValue2() {
        return value2;
    }

    public void setCondition(boolean condition) {
        this.condition = condition;
    }

    public void setValue1(String value1) {
        this.value1 = value1;
    }

    public void setValue2(String value2) {
        this.value2 = value2;
    }

    public Request(boolean condition, String value1, String value2) {
        super();
        this.condition = condition;
        this.value1 = value1;
        this.value2 = value2;
    }

}
View Code

相关文章:

  • 2022-01-05
  • 2021-05-21
  • 2022-12-23
  • 2021-12-03
  • 2021-05-29
  • 2022-12-23
  • 2021-06-23
猜你喜欢
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2022-02-09
  • 2022-12-23
相关资源
相似解决方案