EasyMock - 模拟对象的期望

发布于 2024-11-16 23:34:36 字数 2271 浏览 2 评论 0原文

我对 EasyMock 还很陌生。我正在尝试为我的 Spring WS 端点编写一个 EasyMock 测试,并继续遇到问题。详细信息如下:

端点:

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "UserCreate")<BR>
public void handleUserCreationRequest(@RequestPayload Element userCreate) throws JDOMException {

        String userName = userNameExp.valueOf(userCreate);
        String loginName = userLoginNameExp.valueOf(userCreate);
        String eMail = eMailExp.valueOf(userCreate);
        String region = regionExp.valueOf(userCreate);
        String department = departmentExp.valueOf(userCreate);
        String businessUnit = businessUnitExp.valueOf(userCreate);

        userManagementService.userCreate(userName, loginName, eMail, 
                region, department, businessUnit);
    }

测试:

@Before<BR>
    public void setUp() throws JDOMException {<BR>
        xPath = createNiceMock(XPath.class);<BR>
        payload = createNiceMock(Element.class);<BR>
        managementService = createStrictMock(UserManagementService.class);<BR>

        serviceEndpoint = new UserManagementServiceEndpoint(managementService);
    }
@Test
    public void testUserCreationHandler() throws JDOMException {

        expect(xPath.valueOf(payload)).andReturn("userName");
        expect(xPath.valueOf(payload)).andReturn("loginName");
        expect(xPath.valueOf(payload)).andReturn("eMail");
        expect(xPath.valueOf(payload)).andReturn("region");
        expect(xPath.valueOf(payload)).andReturn("department");
        expect(xPath.valueOf(payload)).andReturn("businessUnit");
        managementService.userCreate("userName", "loginName", "eMail", 
                "region", "department", "businessUnit");
        expectLastCall();
        replayAll();

        serviceEndpoint.handleUserCreationRequest(payload);
        verifyAll();
    }

错误消息:

Failed tests:
  testUserCreationHandler(com.xxx.usermanagement.endpoint.UserManagementServiceEndpoint
Test):
  Expectation failure on verify:
    valueOf(EasyMock for class org.jdom.Element): expected: 6, actual: 0

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0<BR><BR>

如果有人可以帮助我,我将不胜感激。提前致谢。

I am fairly new to EasyMock. I am trying to write a EasyMock test for my Spring WS Endpoint and keep running to a issue. Details are listed below:

Endpoint:

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "UserCreate")<BR>
public void handleUserCreationRequest(@RequestPayload Element userCreate) throws JDOMException {

        String userName = userNameExp.valueOf(userCreate);
        String loginName = userLoginNameExp.valueOf(userCreate);
        String eMail = eMailExp.valueOf(userCreate);
        String region = regionExp.valueOf(userCreate);
        String department = departmentExp.valueOf(userCreate);
        String businessUnit = businessUnitExp.valueOf(userCreate);

        userManagementService.userCreate(userName, loginName, eMail, 
                region, department, businessUnit);
    }

Test:

@Before<BR>
    public void setUp() throws JDOMException {<BR>
        xPath = createNiceMock(XPath.class);<BR>
        payload = createNiceMock(Element.class);<BR>
        managementService = createStrictMock(UserManagementService.class);<BR>

        serviceEndpoint = new UserManagementServiceEndpoint(managementService);
    }
@Test
    public void testUserCreationHandler() throws JDOMException {

        expect(xPath.valueOf(payload)).andReturn("userName");
        expect(xPath.valueOf(payload)).andReturn("loginName");
        expect(xPath.valueOf(payload)).andReturn("eMail");
        expect(xPath.valueOf(payload)).andReturn("region");
        expect(xPath.valueOf(payload)).andReturn("department");
        expect(xPath.valueOf(payload)).andReturn("businessUnit");
        managementService.userCreate("userName", "loginName", "eMail", 
                "region", "department", "businessUnit");
        expectLastCall();
        replayAll();

        serviceEndpoint.handleUserCreationRequest(payload);
        verifyAll();
    }

Error Message:

Failed tests:
  testUserCreationHandler(com.xxx.usermanagement.endpoint.UserManagementServiceEndpoint
Test):
  Expectation failure on verify:
    valueOf(EasyMock for class org.jdom.Element): expected: 6, actual: 0

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0<BR><BR>

I would appreciate if anyone can help me on this. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心作怪 2024-11-23 23:34:36

这里的问题是您的 XPath 模拟对象未设置为您的 UserManagementServiceEndpoint 对象。
您应该修改构造函数以接受 XPath 参数,或者为其创建一个 setter。

The problem you have here is that your XPath mock object is not set to your UserManagementServiceEndpoint object.
You should either modify the constructor to accept an XPath parameter or create a setter for it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文