title: EasyMock void method
body: <p>I'm trying to use EasyMock to mock out some database interface so I can test the business logic off a wrapping method. I've been going ok with methods that return by using the following in my setup of my test. </p>
  
  <pre><code>DBMapper dbmapper = EasyMock.createMock(DBMapper.class);
  userService.setDBMapper(dbmapper);        
  </code></pre>
  
  <p>then within my actual test I run </p>
  
  <pre><code>EasyMock.expect(dbmapper.getUser(userId1)).andReturn(mockUser1);
  EasyMock.replay(dbmapper);
  userService.getUser(userId1);
  </code></pre>
  
  <p>This service then connects to the dbmapper and returns the object (the mapper is injected using setter methods)</p>
  
  <p>These type of mocks seem to work fine. However when I try to run a test for </p>
  
  <pre><code>userService.addUser(newUser1);
  </code></pre>
  
  <p>This method calls a void method.</p>
  
  <pre><code>dbmapper.createUser(newUser);
  </code></pre>
  
  <p>It's this method that I'm having problems mocking out.
  I've tried the following</p>
  
  <pre><code>EasyMock.expectLastCall();
  EasyMock.replay(dbMapper);
  userService.addUser(newUser1);
  </code></pre>
  
  <p>as some other posts/questions etc seem to suggest I get an <code>IlligalStateException: no last call on a mock available</code> </p>
  
  <p>Can anyone point me in the right direction please? </p>
  
  <p>Many Thanks in advance</p>