Closed GoogleCodeExporter closed 9 years ago
Patch files attached (sorry for 2 files, I'm new to SVN and for some reason it
refused to make one patch at the root). Let me know if there are any problems
or
questions.
Original comment by amur...@gmail.com
on 17 Apr 2009 at 7:41
Attachments:
Thanks, I'm looking at it
Original comment by szcze...@gmail.com
on 20 Apr 2009 at 10:16
It's checked in to trunk. I did some minor changes but essentially all went to
trunk.
Some things might change, though. Before the release we might get rid of
CALLS_REAL_METHODS because we want the spy() method to do this (because we would
rather have single method to do the same thing). Obviously this require some
work on
spy() method...
There is one thing you have to be aware of regarding your implementation. Mock
objects are instantiated by Objenesis and therefore their state is messed up
(e.g.
fields are not initiated). If you doCallRealMethod() on a method that depends
on the
state of the object (e.g. uses a field) then you will stop smiling :)
Original comment by szcze...@gmail.com
on 21 Apr 2009 at 7:20
Thanks! When are you planning the next release?
Yes, I've already encountered your point about the object state. It's not a
huge
problem because the internal fields are still settable, you just need to call
the
real setters (which can be done now!) Alternatively, you can use reflection to
inject the values (see InjectionUtils from Unitils). This isn't pretty, but I'm
working with some really ugly legacy code here in the real world :)
Original comment by amur...@gmail.com
on 21 Apr 2009 at 7:53
Hi,
I'm about to hide Mockito.CALLS_REAL_METHODS because I changed the code behind
the
spy() so that the spy actually does it. Does it make sense?
Original comment by szcze...@gmail.com
on 12 May 2009 at 3:10
Could you post the API or code fragment to clarify what you are planning to do?
Thanks!
Original comment by amur...@gmail.com
on 12 May 2009 at 5:30
Sure,
Instead of:
mock(Foo.class, CALLS_REAL_METHODS);
You write:
spy(fooInstance);
Original comment by szcze...@gmail.com
on 12 May 2009 at 5:44
:) thanks.
Here's what the doc says now:
Spying on real objects is often associated with "partial mocking" concept. However,
Mockito spies are not partial mocks. Mockito spy is meant to help testing other
classes - not the spy itself. Therefore spy will not help if you intend to
verify if
method calls other method on the same object. In this case I suggest being
OO/SRPy
(for example you might extract new class/interface...)
So... what will be the change in spy behavior that will make it usable as a
partial mock?
Will I be able to do this, for example:
// setup
mySpy = spy(fooInstance);
when(mySpy.getValue()).thenReturn(47);
// test doSomething()
// this should NOT call the real getValue
mySpy.doSomething();
verify(mySpy).getValue();
Original comment by amur...@gmail.com
on 12 May 2009 at 6:47
yup, the docs are somewhat deprecated according to my last change to spy()
Pretty much you got that right with the example if doSomething() calls
this.getValue() internally.
Original comment by szcze...@gmail.com
on 12 May 2009 at 7:14
Original comment by szcze...@gmail.com
on 9 Jun 2009 at 3:15
Original issue reported on code.google.com by
amur...@gmail.com
on 15 Apr 2009 at 5:12