Interface PowerMockitoStubber

All Superinterfaces:
org.mockito.stubbing.BaseStubber, org.mockito.stubbing.Stubber
All Known Implementing Classes:
PowerMockitoStubberImpl

public interface PowerMockitoStubber extends org.mockito.stubbing.Stubber
Setup stubbing for private or void methods in final class, final void methods, or static (final) methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    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... arguments)
    Allows to mock a static private method based on method name and parameters when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style.
    <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 interface org.mockito.stubbing.BaseStubber

    doAnswer, doCallRealMethod, doNothing, doReturn, doReturn, doThrow, doThrow, doThrow

    Methods inherited from interface org.mockito.stubbing.Stubber

    when
  • Method Details

    • when

      void when(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(Class)

      Mockito.doAnswer(Answer)

      Mockito.doNothing()

      Mockito.doReturn(Object)

      Parameters:
      classMock - the mock class
      See Also:
      • Mockito
    • when

      <T> PrivatelyExpectedArguments when(T mock, Method method) throws Exception
      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)

      Parameters:
      mock - the method
      method - private method to be mocked
      Throws:
      Exception
      See Also:
      • Mockito
    • when

      <T> void when(T mock, Object... arguments) throws Exception
      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)

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

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

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

      <T> PrivatelyExpectedArguments when(Class<T> classMock, Method method) throws Exception
      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)

      Parameters:
      classMock - class owner of private static method
      method - private static method to be mocked
      Throws:
      Exception
      See Also:
      • Mockito
    • when

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

      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

      <T> void when(Class<T> classMock, String methodToExpect, Object... arguments) throws Exception
      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)

      Parameters:
      classMock - the class owner of static private method
      methodToExpect - name of method which have to mocked
      arguments - array of arguments of methodToExpect
      Throws:
      Exception
      See Also:
      • Mockito