Search code examples
javaunit-testingparametersmockingjmock

Using jmock how to reuse parameter


I'm building a test, in which I need to send question, and wait for the answer. Message passing is not the problem. In fact to figure out which answer corresponds to which question, I use an id. My id is generated using an UUID. I want to retrieve this id, which is given as a parameter to a mocked object. It look like this:

oneOf(message).setJMSCorrelationID(with(correlationId));
    inSequence(sequence);

Where correlationId is the string I'd like to keep for an other expectation like this one:

   oneOf(session).createBrowser(with(inputChannel), 
           with("JMSType ='pong' AND JMSCorrelationId = '"+correlationId+"'"));

have you got an answer?


Solution

  • One more option to consider, where does the correlation ID come from? Should that activity be injected in so that you can control it and check for it in the test?