Closed GoogleCodeExporter closed 8 years ago
The latest snapshots already support this. Currently, the spied-on instance is
created implicitly as part of the `Spy()` call:
def foo = Spy(Foo, constructorArgs: [...])
Mockito's solution of passing an existing instance to the `spy` method may seem
nicer but in fact employs dark magic. It doesn't use the existing instance at
all except for copying all its field values to another instance. I'd rather
want to avoid this. Anyway, the outcome is the same.
Original comment by pnied...@gmail.com
on 16 Jul 2012 at 9:47
In my case spied-on instance is created via factory class using the create
method with parameters.
Supporting constructor only initialization could be very limiting, some objects
may have private constructor and static method to create objects.
Could it be supported when spied-on instance is an interface implementation?
I'm assuming in this case no fields copying is needed.
def foo = Spy(Foo, impl: fooImpl)
in this case Foo.class is required to be an interface.
Original comment by denis.st...@gmail.com
on 16 Jul 2012 at 10:19
With Mockito's approach, field copying is always necessary. This makes it scary
because the test isn't actually using the provided instance. In the case where
the instance has to be created with a factory it's probably the only way out
though. I'll have to think whether we want to support that.
Original comment by pnied...@gmail.com
on 16 Jul 2012 at 10:31
We now support spying in general. If you need spying on an existing instance,
please open another issue.
Original comment by pnied...@gmail.com
on 4 Oct 2012 at 6:50
Original issue reported on code.google.com by
denis.st...@gmail.com
on 16 Jul 2012 at 9:39