• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

EasyMock, mixing class extenstion and normal mocking in same unit test  RSS feed

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am having a problem with EasyMock, I have a test that requires the mocking of an object (I have achived this).
However the Object (A) then calls another object (I) (which has an interface) which should throw an exception.

Now both A and I both implment the same interface, what has happened is i am wrapping/decorating(?) an object of type I to provide some logging.

So the client calls A.methodX, which maps though to I.methodX, so I would expect two calls to methodX.

however EasyMock only seems to recognise the calls to A and not to the internal object of A that is represented by I.

Sorry I dont know how to make that make anymore sense.

Any ideas?
I am on the verge of just making teh whole test use class Extension.
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A small code example to help:



A is being moced as classes extension, while something/I is using normal EasyMock.

Thanks
[ May 27, 2008: Message edited by: Gavin Tranter ]
 
author & internet detective
Posts: 39285
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gavin,
Can you post a bit of test code that illustrates the problem?
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,
Seems it was user error :S
I kinda got locked in on my mock objects, but the object I was mocking using class extension I actually want to fully test rather then mock!!

Here is what I was attempting, I still get Expectation errors, but I think it is down to loosing sight of teh woods for the trees.
I tried to keep it genric the example generic and compact.

Thanks
Gavin

 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you ask EasyMock to create a mock object for "ClassToMock.class", you're effectively getting back a completely mocked out fake thing. In other words, whatever methods you invoke on that mock object, the only thing that happens is what would happen with a mock created for an interface -- the original code is not executed.
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse,
Yeah I got that now, I kinda of knew that, but this is my first time with easyMock.

What happened was cos I was mocking everything else, I just mocked what I changed and I didnt realise that my purpose was actual to test what I had change not mock out I had changed

I felt a teeny bit dumb when one of the senior guys pointed this out
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!