Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 意外的方法调用easymock_Java_Junit_Easymock - Fatal编程技术网

Java 意外的方法调用easymock

Java 意外的方法调用easymock,java,junit,easymock,Java,Junit,Easymock,我的SpringMVC控制器中有这样的方法 @RequestMapping(method = RequestMethod.POST) public ModelAndView send(@RequestParam(value = "t", required = false) String t, @RequestParam(value = "s", required = false) String s, @RequestParam(value = "p", requi

我的SpringMVC控制器中有这样的方法

@RequestMapping(method = RequestMethod.POST)
public ModelAndView send(@RequestParam(value = "t", required = false) String t,
        @RequestParam(value = "s", required = false) String s,
        @RequestParam(value = "p", required = false) String p,
        @RequestParam(value = "c", required = false) String c,
        @RequestParam(value = "o", required = false) String o,
        @RequestParam(value = "s", required = false) String s,
        @RequestParam(value = "to", required = false) String to,
        @RequestParam(value = "cc", required = false) String cc,
        @RequestParam(value = "bcc", required = false) String bcc,
        @RequestParam(value = "url", required = false) String url,
        @RequestParam(value = "pd", required = false) String pd) {

    RRS status = validate(new PV(t), new PV(to),
            new PV(o), new PV(s));
    if (status != null) {
        return response(status.getCode(), status.getMessage());
    }

    NM nM = buildMessage(t, s, p,
            c, o, s, to, cc, bcc, url, pd);
    service.store(nM);

    nP.send(nM.getUid());

    return response(nM.getUid());
}
我想测试一下这部分

    RRS status = validate(new PV(t), new PV(to),
            new PV(o), new PV(s));
    if (status != null) {
        return response(status.getCode(), status.getMessage());
    }
但是当我创建这样的测试方法时

@Test
public void testSendMethod() {
    NC controller = createMock(NC.class);
    PV validator = createMock(PV.class);
    expect(controller.validate(validator)).andReturn(null);
    expect(validator.isValid()).andReturn(true);
    replay(validator);
    replay(controller);

    controller.send(T, S, P, C, O, S, TO, CC,
            BCC, URL, PD);
    verify(validator);
    verify(controller);
}
我有个错误

Unexpected method call NC.send("TValue", "SValue" .... /*my parameters values*/ ):
NC.validate(EasyMock for class PV): expected: 1, actual: 0
方法
validate
如下所示

 protected RRS validate(INV... validations) {
    RRS resp = null;
    for (IN validation : validations) {
        if (!validation.isValid()) {
            resp = validation.errorResponse();
            break;
        }
    }
    return resp;
}

有什么问题吗?我想我设置了正确的方法调用顺序,返回值也应该可以…

您在模拟测试对象。那没有道理。您必须创建真正的NC对象,而不是模拟它。只有合作者才应该被嘲笑。我相信你在寻找一个局部的嘲笑。我以前回答过部分模拟问题。答案。您需要部分模拟
NC
类,然后添加
validate
方法作为模拟方法。然后调用send将调用实际的send方法,但可能需要调用validate。