java - How do I ignore call to void method in EasyMock -


i have anonymous inner class added in tested class.

class totest{      private mymanager mymanager      public void seymymanager(mymanager mymanager){        this.mymanager = mymanager;     }       ....     public void dosomething(){     ...         mymanager.addlistener(new listener(){...});     .....       } } 

where manager class other package used in method test body.

how ignore addlistener call?

p.s. ignore = not want make checks calling mymanager.addlistener(..) methods

there's couple of ways this.

my preferred way explicit expectations this:

mymanager mymanager = easymock.createmock(mymanager.class); ... mymanager.addlistener(easymock.isa(listener.class)); ... replay(mymanager); 

the important bit here easymock.isa match expectation against listener passed. prefer way when there's problem elsewhere test fails.

alternatively can use nice mock:

mymanager mymanager = easymock.createnicemock(mymanager.class); ... replay(mymanager); 

however, missing expections may not cause test fail, why don't creating mocks way.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -