2014-09-30 62 views
1

想象的屬性值,我有一個EasyMock的測試中,我有以下行:檢查在EasyMock的匹配

final IRunControl runControl = createMock(IRunControl.class); 
runControl.setSomething(isA(ISomething.class)); 
EasyMock.expectLastCall().once(); 

ISomething看起來是這樣的:

interface ISomething 
{ 
    int getValue1(); 

    String getValue2(); 
} 

是否有可能使runControl.setSomething(isA(ISomething.class))檢查適當的值?

I.e。做類似

runControl.setSomething(
    and(
     isA(ISomething.class), 
     and(propertyValue("value1", 123), propertyValue("value2", "expectedValue2"))) 

回答

2

你需要的是使用Capture

一個例子:

// setup: data 
    ISomething fooSomething = ISomethingImpl(5, "bar"); 

    // setup: expectations 
    Capture<ISomething> capturedISomething = new Capture<ISomething>(); 
    mockCollaborator.setSomething(capture(capturedISomething)); 

    // exercise 
    replay(mockCollaborator); 
    sut.dooWhateverThatInvokesTheCollaboratorSetter(fooSomething); 

    // verify 
    verify(mockCollaborator); 
    assertEquals(5, capturedISomething.getValue().getValue1()); 
    assertEquals("bar", capturedISomething.getValue().getValue2());