• 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

EasyMock: mocking a call to the same object

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question about EasyMock. I find that I am unable to mock calls to another method within the object (via this.). For example, I have 2 methods:

public A performTransformation(B b){
Log.addLogEntry();
return transform(b);
}
public A transform(B b)

I can test Log.addLogEntry and transform with JUnit. However, I want to test performTransformation. I don't really want to test transform or Log.addLogEntry again so I thought that I could use EasyMock. I can mock Log, but I can't add an expect for transform. Is there anyway to do this?

In the meantime, we've moved transform to another object and mocked that, however, this seems incorrect.

Any suggestions?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could simply create an anonymous subclass of the class you're testing and override the method you don't want to exercise:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic