Piotr Gabryanczyk’s Blog

Java, Refactoring, AOP, Spring, DDD, TDD, etc.

  • Blogroll

    • I have joined Anti-IF Campaign

Mocking difficult objects like HttpServletRequest with CGLIB

Posted by Piotr Gabryanczyk on May 19, 2008

Why haven’t I seen this before?
http://www.sixlegs.com/blog/java/concrete-mock-objects.html

Advertisements

4 Responses to “Mocking difficult objects like HttpServletRequest with CGLIB”

  1. Since 2003, this has been integrated into a lot of mocking frameworks (EasyMock class extensions, Mockito…), so it’s not really an issue any more, is it?

  2. I was always using JMock, but maybe even this is not a good excuse… 🙂
    …Acctually JMock was always a bit more dogmatic than other frameworks, so maybe it does not support it…
    I guess they use the rule: mock or stub only classes or interfaces you own

    But when I think about it – it doesn’t make sense when you test boundaries of your system – interactions with external modules or systems…

    Either way I discovered it so late… that maybe I should be ashamed, instead posting it on my blog…
    Anyway, if there is at least one person who learns form it I think it was worth it! 🙂

    Thanks for comment Mwanji.

  3. 🙂

    Actually, I’ve kind of been wondering about this issue. For example, in Michael Feathers’ “Working Effectively With Legacy Code”, he does a lot Extract Interface refactorings, to bring classes under test. Now that you can mock concrete classes, this isn’t necessary, but is it better? Was introducing all those interfaces a good design approach? Maybe not, but maybe if your mocking framework is too powerful, then your design can be sloppier?

  4. I guess we were talking about different things. I know that frameworks like JMock can mock classes instead of interfaces and they use CGLIB for that.
    I was talking about stubbing some functionality without implementing the whole complex interface like in HttpServletRequest.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: