ahmaddarawshi / powermock

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

rename PowerMockito#mock to PowerMockito#powermock #138

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to suggest renaming the PowerMockito#mock methods to
PowerMockito#powermock. The reason for this is to allow the PowerMockito
and vanilla Mockito mock methods both to be used through static imports.
Currently you can only use one of them in this way per compilation unit.

It seems reasonable to restrict usage of PowerMock mocking to those classes
that actually need it, and avoid the @PrepareForTest arguments for those
classes that can be mocked using Mockito.

Backwards compatibility needn't be an issue; leave the current methods and
deprecate them, delegating to powermock().

Aside:
On the other hand, perhaps a more complete solution would be to do away
with the PowerMockito methods all together, instead mocking the Mockito
class to work for all classes that PowerMockito is able to mock, allowing
the user to say Mockito#mock(String.class) or whatever and leaving the
PowerMock infrastructure to decide what to do.

(This is an enhancement request, not a defect.)

Original issue reported on code.google.com by joe.kear...@gtempaccount.com on 12 Aug 2009 at 1:42

GoogleCodeExporter commented 9 years ago
Thanks for your input. We will take it into consideration when developing the
PowerMockito extension in PowerMock 1.3. Our goal is to have much improved 
support
for Mockito in 1.3. 

The reason why the method is called the same as in plain Mockito is that we'd 
like
PowerMockito to be a replacement for Mockito where needed. EasyMock 
classextensions
provides the same mechanism for plain EasyMock, i.e. just replace the
EasyMock#createMock method with EasyMockClassExtension#createMock method to 
support
the mocking of classes. The class extensions then delegates to plain EasyMock 
if the
type is an interface. The philosophy for PowerMockito has been along these 
lines as
well so far. 

Original comment by johan.ha...@gmail.com on 12 Aug 2009 at 2:46

GoogleCodeExporter commented 9 years ago
Ah, so is the intention that all mocking when using PowerMock and Mockito 
should go
through PowerMockito, even when the class is non-final etc. and can be handled
normally by Mockito, but only requiring the @PrepareForTest annotation for those
classes that need special treatment?

That makes sense. Thanks for clarifying that.

Original comment by joe.kear...@gtempaccount.com on 12 Aug 2009 at 3:02

GoogleCodeExporter commented 9 years ago
Yes that's the intention. You can still mix and match Mockito and PowerMockito, 
only
using the features of PowerMockito when you need them. At least that's the goal 
:)

Original comment by johan.ha...@gmail.com on 13 Aug 2009 at 6:18

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 1 Sep 2009 at 1:20