2011-06-26 84 views
0

我對EasyMock來說相當新穎。我正在嘗試爲我的Spring WS Endpoint編寫一個EasyMock測試,並繼續遇到問題。詳情如下所列:EasyMock - 模擬對象的期望

端點:

​​

測試:

@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> 

竟被我如果有人能幫助我,請欣賞。提前致謝。

回答

1

您在這裏遇到的問題是您的XPath模擬對象未設置爲您的UserManagementServiceEndpoint對象。 您應該修改構造函數以接受XPath參數或爲其創建setter。