mocking - How to use Jmock to produce mock Json request? -


in our code json object activemq , decide action , other parameter action , return json object activemq. unit test have mock json object request.

what mock action instead?

@mock private action action;  private actiondispather subject = new actiondispather(action);  @test public void doaction1givensomestateistrue() throws throwable {     final message message = new message();     message.setstate(true);     //message (json object in case) population omitted      context.checking(new expectations() {         {              oneof(action).doaction1();         }     });      subject.on(message); }  @test public void doaction2givensomestateisfalse() throws throwable {     final message message = new message();     message.setstate(false);     //message (json object in case) population omitted      context.checking(new expectations() {         {              oneof(action).doaction2();         }     });      subject.on(message); }  

the json parsing handled in consumer, therefore action decision test json agnostic.

public class consumer {     private actiondispatcher dispatcher;             public void on(activemqmessage message) {          message m = convertfrom(message);          dispatcher.on(m);     } } 

anyway, mock behavior not data.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -