Class 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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addAnswersForStubbing​(MockitoMethodInvocationControl invocationControl)  
      private void assertNotNull​(java.lang.Object object, java.lang.String name)  
      private <T> void prepareForStubbing​(T mock)  
      void when​(java.lang.Class<?> classMock)
      Allows to choose a static method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
      <T> void when​(java.lang.Class<T> classMock, java.lang.Object... arguments)
      Allows to mock a static private method based on the parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
      <T> PrivatelyExpectedArguments when​(java.lang.Class<T> classMock, java.lang.reflect.Method method)
      Allows to mock a static private method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
      <T> void when​(java.lang.Class<T> classMock, java.lang.String methodToExpect, java.lang.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)
      Supports PowerMockito mocks.
      <T> void when​(T mock, java.lang.Object... arguments)
      Allows to mock a private instance method based on the parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
      <T> PrivatelyExpectedArguments when​(T mock, java.lang.reflect.Method method)
      Allows to mock a private instance method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
      <T> void when​(T mock, java.lang.String methodToExpect, java.lang.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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.mockito.stubbing.Stubber

        doAnswer, doCallRealMethod, doNothing, doReturn, doThrow, doThrow
    • Constructor Detail

      • PowerMockitoStubberImpl

        public PowerMockitoStubberImpl()
    • Method Detail

      • when

        public void when​(java.lang.Class<?> classMock)
        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(Throwable)

        Mockito.doAnswer(Answer)

        Mockito.doNothing()

        Mockito.doReturn(Object)

        See examples in javadoc for Mockito

        Specified by:
        when in interface PowerMockitoStubber
      • when

        public <T> T when​(T instanceMock)
        Supports PowerMockito mocks. If mock is not a PowerMockito mock it will delegate to Mockito.
        Specified by:
        when in interface org.mockito.stubbing.Stubber
        Overrides:
        when in class org.mockito.internal.stubbing.StubberImpl
        See Also:
        Stubber.when(Object)
      • when

        public <T> PrivatelyExpectedArguments when​(T mock,
                                                   java.lang.reflect.Method method)
                                            throws java.lang.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(Throwable)

        Mockito.doAnswer(Answer)

        Mockito.doNothing()

        Mockito.doReturn(Object)

        See examples in javadoc for Mockito

        Specified by:
        when in interface PowerMockitoStubber
        Throws:
        java.lang.Exception
      • when

        public <T> void when​(T mock,
                             java.lang.Object... arguments)
                      throws java.lang.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)

        See examples in javadoc for Mockito

        Specified by:
        when in interface PowerMockitoStubber
        Throws:
        java.lang.Exception
      • when

        public <T> void when​(T mock,
                             java.lang.String methodToExpect,
                             java.lang.Object... arguments)
                      throws java.lang.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)

        See examples in javadoc for Mockito

        Specified by:
        when in interface PowerMockitoStubber
        Throws:
        java.lang.Exception
      • when

        public <T> void when​(java.lang.Class<T> classMock,
                             java.lang.Object... arguments)
                      throws java.lang.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)

        See examples in javadoc for Mockito

        Specified by:
        when in interface PowerMockitoStubber
        Throws:
        java.lang.Exception
      • when

        public <T> void when​(java.lang.Class<T> classMock,
                             java.lang.String methodToExpect,
                             java.lang.Object... parameters)
                      throws java.lang.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)

        See examples in javadoc for Mockito

        Specified by:
        when in interface PowerMockitoStubber
        Throws:
        java.lang.Exception
      • when

        public <T> PrivatelyExpectedArguments when​(java.lang.Class<T> classMock,
                                                   java.lang.reflect.Method method)
                                            throws java.lang.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)

        See examples in javadoc for Mockito

        Specified by:
        when in interface PowerMockitoStubber
        Throws:
        java.lang.Exception
      • assertNotNull

        private void assertNotNull​(java.lang.Object object,
                                   java.lang.String name)
      • prepareForStubbing

        private <T> void prepareForStubbing​(T mock)