I recently blogged about getting started with EasyMock - a simple framework for taking the pain out of creating and using mock objects when unit testing your java code. In the example I showed that we were expecting the next() method to be called and we wanted the mock ResultSet to return false: expect(mockResultSet.next()).andReturn(false); What I didn't explain was that you use the expect() method when you are expecting the mock to return a value. If the method doesn't return a value (such as ResultSet.close() ) then there is no need to wrap it in an expect() method call: mockResultSet.close(); Remember: any methods that you call on your mock prior to the replay() method call are setting up it's expectations not actually calling the methods. After the replay() method is called the mock is in 'live' mode, recording activity and returning any predefined values when it's methods are called. So here is the same example with the additional expected close()
eng mgr / leader / full stack / java / agile / tdd / security / aws / go