title: EasyMock newbie: how to override a method to behave differently, not just return a different value
body: <p>I am learning unit testing and mocking.  I have JUnit running, and instead of using a Mocking Framework, I have manually created mock classes by extending existing classes and interfaces.  I would like to learn the mocking framework EasyMock because thats all thats available here at my work.  While you might suggest some other mocking framework, they will not be available to me.</p>
  
  <p>The Setup:</p>
  
  <p>I have a View and a Presenter and a API backend.  When the user clicks a button: "Check For Updates", the view calls the <code>presenter.checkForUpdates()</code> which does a call to <code>api.checkForUpdates()</code> and expects an callback.  If the an exception occurs, the api will notify the presenter via a callback, and the controller will call the view method <code>view.showUserError()</code>.  Callbacks are used not return parameters because of the async nature of hitting our API bac
  kend.</p>
  
  <p>The Object under test is the <code>Presenter</code>.  Specifically, I want to test that the <code>View.showUserError()</code> gets called when an exception occurs in the Api.  I believe I can mock <code>Api.checkForUpdates()</code> to immediately call the exception callback instead of doing an actual network call.</p>
  
  <p>The problem is, I only see EasyMock mocking return values.  For example:</p>
  
  <p><code>EasyMock.expect(api.checkForUpdates()).andReturn(xxxx)</code></p>
  
  <p>wont work for me, since <code>api.checkForUpdates()</code> does not return anything and instead does a callback.  What I really want to do is something like:</p>
  
  <p><code>EasyMock.expect(api.checkForUpdates()).andExecute(exceptionCallback(NetworkError));</code></p>
  
  <p>But I don't see how to do that.  Is there something that can do what I want or am I missing something basic?</p>
  
  <p>Thanks</p>