Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Testing a Class that uses lookup-method injection

  1. #11
    Join Date
    Jul 2005
    Location
    Seattle, WA, USA
    Posts
    5

    Default

    Quote Originally Posted by costin
    Use 1.2 versions - there is a good explanation on the site about the differences between them. I use also JDK 1.4.2.
    Btw, easy mock is also used by Spring for testing. Convinced? :)
    Heh jeez, now I see it :)
    Thanks for your help, I'll give that a shot.
    -Justin

  2. #12
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    or use mocks (see easy mock).
    It's true EasyMock will work for classes, but I tend to only use mocks for Collaborators, not the actual class I'm testing. In this scenario, I'd still subclass ContextInterceptor.

  3. #13
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Generally speaking, mocking interfaces is the preferred way

    You can mock classes (with cglib) so long as they are not final and do not contain any final methods in them.

    I don't really get how using mocks in this instance helps anyway AFAIK you cannot "partially" mock a class, so you couldn't create a class where the get*RequestContext was mocked, but the preHandle was native code. You either have a "native" class, or a mocked class.

    Maybe I am missing something

  4. #14
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    I don't really get how using mocks in this instance helps anyway Smile AFAIK you cannot "partially" mock a class, so you couldn't create a class where the get*RequestContext was mocked, but the preHandle was native code. You either have a "native" class, or a mocked class.
    You can use delegation so basically the methods you don't require simply delegate to the parent class. Moreover you can finalize the methods you don't want to extends, CGLIB will just throw a warning and that's all.
    Indeed in this case you'd better off extending the initial class but mocking is sometimes better because you can mimic the behaviour without wiring the colaborators as you are in charge of your object behaviour (without the need of rewriting it 'per-se').
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #15
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    So if you mock a class, the methods you don't explictly mock just fall through to the native class?

    Thats's pretty cool. I only ever mock interfaces, so it isn't really a problem for me

  6. #16
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Better just read the documentation on mocking - mocks basically just proxyies your object. I was just saying that if you want to unmock a method (like you said) and make it actually perform something on the native class use the final keyword.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 1
    Last Post: Jul 28th, 2005, 05:08 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •