Reputation: 2882
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.
Upvotes: 0
Views: 1144
Reputation: 403581
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.
Upvotes: 1