If a method of a class which will be mocked by easymock did return some value, you should specify the return value explicitly before you use the mock object in your unit test case. or else easymock will complain:
Java. Lang. illegalstateexception: Missing behavior definition for the preceeding method callXxx
An example:
Say we have a interface named subject which has a member method as follows:
Public interface subject {<br/> callback addobserver (callback newobserver); <br/>}< br/>
Then we shoshould use easymock to mock this interface in following way:
Public void testregisterobserver () throws exception {<br/> subject mocksubject = easymock. createnicemock (subject. class); <br/> callback mockcallback = easymock. createnicemock (callback. class); <br/> easymock. wrong CT (mocksubject. addobserver (easymock. <callback> notnull ())). andreturn (mockcallback); <br/> easymock. replay (mocksubject); <br/> // test code here... <br/> easymock. verify (mocksubject); <br/>}
Note the line containsAndreturn. If you missed the call to andreturn, easymock will throw out the above illegalstateexception.