Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] stubs (or mocks that ignore method calls)

Jay Fields

2008-10-24

Replies: Find Java Web Hosting

Author LoginPost Reply
Okay, I've only just started working with JMock.

Assume the following test

    @Test
    public void shouldTestSomething() {
        final Subscriber subscriber = mockery.mock(Subscriber.class);
        final Callback callback = mockery.mock(Callback.class);
        mockery.checking(new Expectations() {
            {
                one(subscriber).subscribe(callback);
                ignoring(callback);
            }
        });
        Workflow workflow = new Workflow(subscriber, callback);
    }

I'm testing that subscribe is called, but I don't care what happens to callback.

It seems like it would be nicer to have the following test:

    @Test
    public void shouldTestSomethingElse() {
        final Subscriber subscriber = mockery.mock(Subscriber.class);
        mockery.checking(new Expectations() {
            {
                one(subscriber).subscribe(with(any(Callback.class)));
            }
        });
        Workflow workflow = new Workflow(subscriber, mockery.stub(Callback.class));
    }

Is there something already in JMock that will allow me to do that?

Cheers, Jay
©2008 gg3721.com - Jax Systems, LLC, U.S.A.