• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 42145
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic