org.jmock.Mock no longer available?

1.1k Views Asked by At

so I added all the jars from jMock 2.5.1

While attempting to follow http://www.ibm.com/developerworks/opensource/library/os-eclipse-rmock/index.html

import org.jmock.Mock;
import org.jmock.cglib.MockObjectTestCase;
public class ServiceClassTest extends MockObjectTestCase {
    private ServiceClass serviceClass;
    private Mock mockCollaborator;
    private ICollaborator collaborator;

    public void setUp(){
        serviceClass = new ServiceClass();
        mockCollaborator = new Mock(ICollaborator.class);
    }

    public void testRunServiceAndReturnFalse(){
        mockCollaborator.expects(once()).method\
              ("executeJob").will(returnValue("failure"));
        collaborator = (ICollaborator)mockCollaborator.proxy();
        boolean result = serviceClass.runService(collaborator);
        assertFalse(result);
    }
}

however, it doesn't work? It cannot find org.jmock.Mock instead suggest Mockery. I tried using Mockery but it doesn't seem to allow passing an argument.

1

There are 1 best solutions below

0
skaffman On BEST ANSWER

That tutorial uses JMock 1, which is obsolete. In JMock 2, the Mock class has been done away with, replaced with Mockery and generics.

Instead of

Mock mockCollaborator = new Mock(ICollaborator.class);

you would do

ICollaborator mockCollaborator  = mockery.mock(ICollaborator.class);

where mockery is a field of type Mockery.

I suggest ignoring that tutorial completely, and using the ones on the JMock website.