File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EasyMockClassExtension not mocking class

 
Gaurav tyagigaurav
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Environment:

SPRING
JUNIT 4.4
EasyMock 2.2
EasyMockClassExtension 2.2

Setup:
Controller to be tested:

The junit I have tried for testing the above controller:

Issue :
The "statusBean.getGroupsAsMap().values()" gives error while trying to fetch the real values, i.e. EasyMock is not mocking this. The class StatusBean does not have any corresponding Interface.

Any pointers would be highly appreciated.

Thanks
GT
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I notice that the reference to the mock is called statusBeen, but you replay feedStatusBean. That looks suspicious to me.

Also, you don't show how you are injecting the statusBean into the code under test. How do you?
 
Gaurav tyagigaurav
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Ilja.

Apologies for the typo. Please see corrections:

EasyMock.replay(feedStatusBean); => EasyMock.replay(statusBean);

Actually this is an existing controller for which i need to write UTs for. There is no default constructor in the StatusBean class. I am not sure if we can inject it anyhow.

Thanks again
GT

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification.

I don't understand what having a default constructor (I assume you mean a no-arg constructor) has to do with injectability. You have a statusBean mock. For the code under test to use it, you need to pass it into the code. How are you doing that?
 
Gaurav tyagigaurav
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ilja

I am not sure how to pass the mock to the class under test. I think thats the issue here then.
Can you please let me know how can i pass the mock in the code?

Thanks
GT
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic