Your problem appears to be that you have two Car
objects. You have a car
, which you set the expectations on, and a mockCar
, which you pass through. Without seeing the definitions of these objects, I can't say for sure, but this is probably the root of your problem.
If this isn't the issue, we're going to need more code. Preferably the entire file(s).
For reference, this compiles fine and passes the tests:
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.Test;
public class TestyMcTestTest {
private final Mockery context = new Mockery();
private final EntityManager em = context.mock(EntityManager.class);
private final Stacker stacker = new Stacker(em);
private final Car mockCar = context.mock(Car.class);
@Test
public void testCar() {
context.checking(new Expectations() {{
oneOf(em).persist(mockCar);
oneOf(mockCar).setEngine(null);
}});
this.stacker.testa(mockCar);
context.assertIsSatisfied();
}
public interface Car {
void setEngine(Engine engine);
}
public interface Engine { }
public class Stacker {
private final EntityManager em;
public Stacker(EntityManager em) {
this.em = em;
}
public void testa(Car car) {
em.persist(car);
car.setEngine(null);
}
}
private interface EntityManager {
void persist(Object o);
}
}