Class PowerMockitoStubberImpl
- java.lang.Object
-
- org.mockito.internal.stubbing.StubberImpl
-
- org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl
-
- All Implemented Interfaces:
org.mockito.stubbing.Stubber,PowerMockitoStubber
public class PowerMockitoStubberImpl extends org.mockito.internal.stubbing.StubberImpl implements PowerMockitoStubber
Extension of the standard Mocktio stubber implementation that also support PowerMockito created mocks.
-
-
Constructor Summary
Constructors Constructor Description PowerMockitoStubberImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidwhen(Class<?> classMock)Allows to choose a static method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style<T> voidwhen(Class<T> classMock, Object... arguments)Allows to mock a static private method based on the parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.<T> PrivatelyExpectedArgumentswhen(Class<T> classMock, Method method)Allows to mock a static private method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.<T> voidwhen(Class<T> classMock, String methodToExpect, Object... parameters)Allows to mock a static private method based on method name and parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.<T> Twhen(T instanceMock)Supports PowerMockito mocks.<T> voidwhen(T mock, Object... arguments)Allows to mock a private instance method based on the parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.<T> PrivatelyExpectedArgumentswhen(T mock, Method method)Allows to mock a private instance method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.<T> voidwhen(T mock, String methodToExpect, Object... arguments)Allows to mock a private instance method based on method name and parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.-
Methods inherited from class org.mockito.internal.stubbing.StubberImpl
doAnswer, doCallRealMethod, doNothing, doReturn, doThrow, doThrow
-
-
-
-
Method Detail
-
when
public void when(Class<?> classMock)
Allows to choose a static method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() styleExample:
doThrow(new RuntimeException()).when(StaticList.class); StaticList.clear(); //following throws RuntimeException: StaticList.clear();
Read more about those methods:Mockito.doThrow(Throwable)Mockito.doAnswer(Answer)Mockito.doNothing()Mockito.doReturn(Object)See examples in javadoc for
Mockito- Specified by:
whenin interfacePowerMockitoStubber
-
when
public <T> T when(T instanceMock)
Supports PowerMockito mocks. Ifmockis not a PowerMockito mock it will delegate to Mockito.- Specified by:
whenin interfaceorg.mockito.stubbing.Stubber- Overrides:
whenin classorg.mockito.internal.stubbing.StubberImpl- See Also:
Stubber.when(Object)
-
when
public <T> PrivatelyExpectedArguments when(T mock, Method method) throws Exception
Description copied from interface:PowerMockitoStubberAllows to mock a private instance method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.Example:
doThrow(new RuntimeException()).when(instance, method("myMethod")).withNoArguments();Read more about those methods:Mockito.doThrow(Throwable)Mockito.doAnswer(Answer)Mockito.doNothing()Mockito.doReturn(Object)See examples in javadoc for
Mockito- Specified by:
whenin interfacePowerMockitoStubber- Throws:
Exception
-
when
public <T> void when(T mock, Object... arguments) throws ExceptionDescription copied from interface:PowerMockitoStubberAllows to mock a private instance method based on the parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.Example:
doThrow(new RuntimeException()).when(instance, parameter1, parameter2);
Read more about those methods:Mockito.doThrow(Throwable)Mockito.doAnswer(Answer)Mockito.doNothing()Mockito.doReturn(Object)See examples in javadoc for
Mockito- Specified by:
whenin interfacePowerMockitoStubber- Throws:
Exception
-
when
public <T> void when(T mock, String methodToExpect, Object... arguments) throws ExceptionDescription copied from interface:PowerMockitoStubberAllows to mock a private instance method based on method name and parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.Example:
doThrow(new RuntimeException()).when(instance, "methodName", parameter1, parameter2);
Read more about those methods:Mockito.doThrow(Throwable)Mockito.doAnswer(Answer)Mockito.doNothing()Mockito.doReturn(Object)See examples in javadoc for
Mockito- Specified by:
whenin interfacePowerMockitoStubber- Throws:
Exception
-
when
public <T> void when(Class<T> classMock, Object... arguments) throws Exception
Description copied from interface:PowerMockitoStubberAllows to mock a static private method based on the parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.Example:
doThrow(new RuntimeException()).when(MyClass.class, parameter1, parameter2);
Read more about those methods:Mockito.doThrow(Throwable)Mockito.doAnswer(Answer)Mockito.doNothing()Mockito.doReturn(Object)See examples in javadoc for
Mockito- Specified by:
whenin interfacePowerMockitoStubber- Throws:
Exception
-
when
public <T> void when(Class<T> classMock, String methodToExpect, Object... parameters) throws Exception
Description copied from interface:PowerMockitoStubberAllows to mock a static private method based on method name and parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.Example:
doThrow(new RuntimeException()).when(MyClass.class, "methodName", parameter1, parameter2);
Read more about those methods:Mockito.doThrow(Throwable)Mockito.doAnswer(Answer)Mockito.doNothing()Mockito.doReturn(Object)See examples in javadoc for
Mockito- Specified by:
whenin interfacePowerMockitoStubber- Throws:
Exception
-
when
public <T> PrivatelyExpectedArguments when(Class<T> classMock, Method method) throws Exception
Description copied from interface:PowerMockitoStubberAllows to mock a static private method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.Example:
doThrow(new RuntimeException()).when(MyClass.class, method("myMethod")).withNoArguments();Read more about those methods:Mockito.doThrow(Throwable)Mockito.doAnswer(Answer)Mockito.doNothing()Mockito.doReturn(Object)See examples in javadoc for
Mockito- Specified by:
whenin interfacePowerMockitoStubber- Throws:
Exception
-
-