Heh jeez, now I see it :)Originally Posted by costin
Thanks for your help, I'll give that a shot.
-Justin
Heh jeez, now I see it :)Originally Posted by costin
Thanks for your help, I'll give that a shot.
-Justin
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.or use mocks (see easy mock).
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 anywayAFAIK 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![]()
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.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.
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
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![]()
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