ahmaddarawshi / powermock

Automatically exported from code.google.com/p/powermock
0 stars 0 forks source link

Partial mocking in the Mockito API doesn't work for non-final methods #98

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Partial mocking the following class doesn't work:

class UnderTest
{
       String test()
       {
               String s = getString();
               System.out.println(s);
               return s;
       }

       String getString() { return "REAL VALUE"; }
}

I.e. we'd like to partial mock the "getString" method and invoke the test
method. If we were to change the modifier of the test method to final then
it would suddenly work. If the modifier is not final the MockGateway never
intercepts the call for some reason. Maybe it's something wrong with the
byte-code manipulation but I'm not sure at this moment. It works fine with
the EasyMock API though. 

Refer to
http://code.google.com/p/powermock/source/browse/trunk/modules/module-test/power
mockito/junit4/src/test/java/samples/powermockito/junit4/partialmocking/PartialM
ockingExampleDefect.java
for an example.   

Original issue reported on code.google.com by johan.ha...@gmail.com on 11 Apr 2009 at 12:23

GoogleCodeExporter commented 9 years ago

Original comment by jan.kron...@gmail.com on 27 Apr 2009 at 4:56

GoogleCodeExporter commented 9 years ago
It doesn't work with Javassist 3.10 or 3.11 either

Original comment by johan.ha...@gmail.com on 8 Jul 2009 at 10:14

GoogleCodeExporter commented 9 years ago
Old mockPartial methods have been removed. You should now use 
PowerMockito.spy(..)
instead

Original comment by johan.ha...@gmail.com on 4 Sep 2009 at 6:15