Class PowerMockitoStubberImpl

java.lang.Object
org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl
All Implemented Interfaces:
org.mockito.stubbing.BaseStubber, org.mockito.stubbing.Stubber, PowerMockitoStubber

public class PowerMockitoStubberImpl extends Object implements PowerMockitoStubber, org.mockito.stubbing.Stubber
Extension of the standard Mocktio stubber implementation that also support PowerMockito created mocks.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.mockito.stubbing.Stubber
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PowerMockitoStubberImpl(org.mockito.stubbing.Stubber stubber)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    assertNotNull(Object object, String name)
     
    org.mockito.stubbing.Stubber
    doAnswer(org.mockito.stubbing.Answer answer)
     
    org.mockito.stubbing.Stubber
     
    org.mockito.stubbing.Stubber
     
    org.mockito.stubbing.Stubber
    doReturn(Object toBeReturned)
     
    org.mockito.stubbing.Stubber
    doReturn(Object toBeReturned, Object... nextToBeReturned)
     
    org.mockito.stubbing.Stubber
    doThrow(Class<? extends Throwable> toBeThrown)
     
    org.mockito.stubbing.Stubber
    doThrow(Class<? extends Throwable> toBeThrown, Class<? extends Throwable>[] nextToBeThrown)
     
    org.mockito.stubbing.Stubber
    doThrow(Throwable... toBeThrown)
     
    void
    when(Class<?> classMock)
    Allows to choose a static method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
    <T> void
    when(Class<T> classMock, Object... arguments)
    Allows to mock a static private method based on the parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
    when(Class<T> classMock, Method method)
    Allows to mock a static private method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
    <T> void
    when(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> T
    when(T instanceMock)
     
    <T> void
    when(T mock, Object... arguments)
    Allows to mock a private instance method based on the parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
    when(T mock, Method method)
    Allows to mock a private instance method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
    <T> void
    when(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 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • stubber

      private final org.mockito.stubbing.Stubber stubber
  • Constructor Details

    • PowerMockitoStubberImpl

      public PowerMockitoStubberImpl(org.mockito.stubbing.Stubber stubber)
  • Method Details

    • when

      public <T> T when(T instanceMock)
      Specified by:
      when in interface org.mockito.stubbing.Stubber
    • doThrow

      public org.mockito.stubbing.Stubber doThrow(Throwable... toBeThrown)
      Specified by:
      doThrow in interface org.mockito.stubbing.BaseStubber
    • doThrow

      public org.mockito.stubbing.Stubber doThrow(Class<? extends Throwable> toBeThrown)
      Specified by:
      doThrow in interface org.mockito.stubbing.BaseStubber
    • doThrow

      public org.mockito.stubbing.Stubber doThrow(Class<? extends Throwable> toBeThrown, Class<? extends Throwable>[] nextToBeThrown)
      Specified by:
      doThrow in interface org.mockito.stubbing.BaseStubber
    • doAnswer

      public org.mockito.stubbing.Stubber doAnswer(org.mockito.stubbing.Answer answer)
      Specified by:
      doAnswer in interface org.mockito.stubbing.BaseStubber
    • doNothing

      public org.mockito.stubbing.Stubber doNothing()
      Specified by:
      doNothing in interface org.mockito.stubbing.BaseStubber
    • doReturn

      public org.mockito.stubbing.Stubber doReturn(Object toBeReturned)
      Specified by:
      doReturn in interface org.mockito.stubbing.BaseStubber
    • doReturn

      public org.mockito.stubbing.Stubber doReturn(Object toBeReturned, Object... nextToBeReturned)
      Specified by:
      doReturn in interface org.mockito.stubbing.BaseStubber
    • doCallRealMethod

      public org.mockito.stubbing.Stubber doCallRealMethod()
      Specified by:
      doCallRealMethod in interface org.mockito.stubbing.BaseStubber
    • when

      public void when(Class<?> classMock)
      Description copied from interface: PowerMockitoStubber
      Allows to choose a static method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style

      Example:

       doThrow(new RuntimeException()).when(StaticList.class);
       StaticList.clear();
      
       //following throws RuntimeException:
       StaticList.clear();
       

      Read more about those methods:

      Mockito.doThrow(Class)

      Mockito.doAnswer(Answer)

      Mockito.doNothing()

      Mockito.doReturn(Object)

      Specified by:
      when in interface PowerMockitoStubber
      Parameters:
      classMock - the mock class
      See Also:
      • Mockito
    • when

      public <T> PrivatelyExpectedArguments when(T mock, Method method) throws Exception
      Description copied from interface: PowerMockitoStubber
      Allows 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(Class)

      Mockito.doAnswer(Answer)

      Mockito.doNothing()

      Mockito.doReturn(Object)

      Specified by:
      when in interface PowerMockitoStubber
      Parameters:
      mock - the method
      method - private method to be mocked
      Throws:
      Exception
      See Also:
      • Mockito
    • when

      public <T> void when(T mock, Object... arguments) throws Exception
      Description copied from interface: PowerMockitoStubber
      Allows 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)

      Specified by:
      when in interface PowerMockitoStubber
      Parameters:
      mock - the Mock
      arguments - array of arguments is used to find suitable method to be mocked.
      Throws:
      Exception
      See Also:
      • Mockito
    • when

      public <T> void when(T mock, String methodToExpect, Object... arguments) throws Exception
      Description copied from interface: PowerMockitoStubber
      Allows 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)

      Specified by:
      when in interface PowerMockitoStubber
      Parameters:
      mock - the Mock
      methodToExpect - name of method which have to mocked
      arguments - array of arguments of methodToExpect
      Throws:
      Exception
      See Also:
      • Mockito
    • when

      public <T> void when(Class<T> classMock, Object... arguments) throws Exception
      Description copied from interface: PowerMockitoStubber
      Allows 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)

      Specified by:
      when in interface PowerMockitoStubber
      Parameters:
      classMock - class owner of private static method
      arguments - array of arguments is used to find suitable method to be mocked.
      Throws:
      Exception
      See Also:
      • Mockito
    • when

      public <T> void when(Class<T> classMock, String methodToExpect, Object... parameters) throws Exception
      Description copied from interface: PowerMockitoStubber
      Allows 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)

      Specified by:
      when in interface PowerMockitoStubber
      Parameters:
      classMock - the class owner of static private method
      methodToExpect - name of method which have to mocked
      parameters - array of arguments of methodToExpect
      Throws:
      Exception
      See Also:
      • Mockito
    • when

      public <T> PrivatelyExpectedArguments when(Class<T> classMock, Method method) throws Exception
      Description copied from interface: PowerMockitoStubber
      Allows 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)

      Specified by:
      when in interface PowerMockitoStubber
      Parameters:
      classMock - class owner of private static method
      method - private static method to be mocked
      Throws:
      Exception
      See Also:
      • Mockito
    • assertNotNull

      private void assertNotNull(Object object, String name)