Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to understand : No Last Call on a Mock available. _ Easy Mocks

 
Ravi C Kota
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

While I was working on some unit tests using EasyMock, I ended up with the exception java.lang.IllegalStateException: no last call on a mock available, quite often.

Below is the program, that needs to be tested.



Now I need to write some unit tests for Main and mocking IInterface, for now

My code is as follows


I need to admit that I have not worked on EasyMocks before and pretty good chances that I did not set it up correctly in my test. But then, I need guidance in setting up the test correctly.

I'm using EasyMock 3.0.

When I ran my test, it is failing with the exception java.lang.IllegalStateException: no last call on a mock available, pointing at line

EasyMock.expect(a.function()).andReturn("test");

Can somebody guide me ?

Thanks
 
Ravi C Kota
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some guidance please.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you call EasyMock.replay(a) ?

Without calling replay, the mock stays in record mode. Then when you call the actual method, the mock is recording and wonders what the return value should be.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic