Ravi
Ravi

Reputation: 1

EasyMock - expectation of mocked object

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.

Upvotes: 0

Views: 1071

Answers (1)

jbleduigou
jbleduigou

Reputation: 139

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.

Upvotes: 1

Related Questions