• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EasyMockClassExtension not mocking class

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
please buy my thing and then I'll have more money:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic