File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes EasyMockClassExtension not mocking class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "EasyMockClassExtension not mocking class" Watch "EasyMockClassExtension not mocking class" New topic
Author

EasyMockClassExtension not mocking class

Gaurav tyagigaurav
Greenhorn

Joined: Jul 30, 2008
Posts: 15
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

Joined: Jul 11, 2001
Posts: 14112
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?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Gaurav tyagigaurav
Greenhorn

Joined: Jul 30, 2008
Posts: 15
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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Jul 30, 2008
Posts: 15
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EasyMockClassExtension not mocking class