Question

I'm writing an integration test that simulates a sequence of actions coming from the front end. I'm setting up my expectations like this:

context.checking(new Expectations() {{
  States state = states("service");

  allowing(service).getPendingTxn();
  will(returnValue(null));
  when(state.isNot("has-pending-txn"));

  one(service).createPendingTxn();
  will(returnValue(txnId));
  then(state.is("has-pending-txn"));

  allowing(service).getPendingTxn();
  will(returnValue(transaction));
  when(state.is("has-pending-txn"));
}});

The code under test then makes the calls in that order.

This isn't working for me. It looks like service.getPendingTxn() is returning a jMock null object, rather than the supplied values. I think I'm doing something wrong when I write both will(...) and when(...) after an expectation, but I'm not sure.

Is there something I'm missing here?

Was it helpful?

Solution

Per Duncan's suggestion, the answer is that that's exactly how you use states. I had another problem in the test that I incorrectly attributed to being related to states.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top