EasyMock: providing arguments you don't know at compile time

Using the latest version of EasyMock, I have a method that I need to disable. The method takes an object parameter and returns void.

The described method is called by the method that I am testing. There are no surprises. My difficulty is that the object that comes as an argument to the mocking method is created by the method I'm testing.

I know that you can get around this with createNiceMock(), but is there a way to explicitly prohibit this method?

Code example:

public interface IMockMe { 
    void doSomething(InnerObj obj);
}

public class TestMe {
    IMockMe mockMe; 

    public void testThisMethod() {
        InnerObj obj = new InnerObj();
        mockMe.doSomething(obj);
    }
}

class Tester {
    @Test
    public void testThatDarnedMethod() {
        IMockMe mocked = EasyMock.create(IMockMe.class);

        mocked.doSomething( /* what goes here? */);
        EasyMock.expectLastCall();

        TestMe testMe = new TestMe(mocked);
        testMe.testThisMethod();

    }
}
+5
source share
1 answer

" " EasyMock. :

String[] documents = new String[] { "Document 1", "Document 2" };
expect(mock.voteForRemovals(aryEq(documents))).andReturn(42);

aryEq(documents) - , , , .

anyObject().

+4

All Articles