0
votes

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?

1
is biState a typo or are there two state objects?Steve Freeman
Thanks. Typo while cleaning up internal names. This is working for me now, I think I may have had another expectation that was hiding the one with the state associated with it.Kevin Peterson
@KevinPeterson Can you post a short answer and accept it so we know this is closed?Duncan Jones

1 Answers

0
votes

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.