-
- All Implemented Interfaces:
-
org.mockito.stubbing.BaseStubber,org.mockito.stubbing.Stubber
@UnstableApi() public class StaticCapableStubber implements Stubber
-
-
Method Summary
Modifier and Type Method Description <T> Twhen(T mock)voidwhen(MockedVoidMethod method)Set up stubbing for a static void method. <T> voidwhen(MockedMethod<T> method)Set up stubbing for a static method. StaticCapableStubberdoThrow(Array<Throwable> toBeThrown)StaticCapableStubberdoThrow(Class<out Throwable> toBeThrown)final StaticCapableStubberdoThrow(Class<out Throwable> toBeThrown, Array<Class<out Throwable>> nextToBeThrown)StaticCapableStubberdoAnswer(Answer answer)StaticCapableStubberdoNothing()StaticCapableStubberdoReturn(Object toBeReturned)StaticCapableStubberdoReturn(Object toBeReturned, Array<Object> nextToBeReturned)StaticCapableStubberdoCallRealMethod()-
Methods inherited from class org.mockito.stubbing.Stubber
when -
Methods inherited from class org.mockito.stubbing.BaseStubber
doAnswer, doCallRealMethod, doNothing, doReturn, doThrow -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
when
<T> T when(T mock)
-
when
@UnstableApi() void when(MockedVoidMethod method)
Set up stubbing for a static void method.
private class C { void instanceMethod(String arg) {} static void staticMethod(String arg) {} }{@literal @}Test public void test() { // instance mocking C mock = mock(C.class); doThrow(Exception.class).when(mock).instanceMethod(eq("Hello)); assertThrows(Exception.class, mock.instanceMethod("Hello")); // static mocking MockitoSession session = mockitoSession().staticMock(C.class).startMocking(); doThrow(Exception.class).when(() -> C.instanceMethod(eq("Hello)); assertThrows(Exception.class, C.staticMethod("Hello")); session.finishMocking(); }- Parameters:
method- The method to stub as a lambda.
-
when
@UnstableApi() <T> void when(MockedMethod<T> method)
Set up stubbing for a static method.
private class C { int instanceMethod(String arg) { return 1; } int static staticMethod(String arg) { return 1; } }{@literal @}Test public void test() { // instance mocking C mock = mock(C.class); doReturn(2).when(mock).instanceMethod(eq("Hello)); assertEquals(2, mock.instanceMethod("Hello")); // static mocking MockitoSession session = mockitoSession().staticMock(C.class).startMocking(); doReturn(2).when(() -> C.instanceMethod(eq("Hello)); assertEquals(2, C.staticMethod("Hello")); session.finishMocking(); }- Parameters:
method- The method to stub as a lambda.
-
doThrow
StaticCapableStubber doThrow(Array<Throwable> toBeThrown)
-
doThrow
StaticCapableStubber doThrow(Class<out Throwable> toBeThrown)
-
doThrow
@SafeVarargs() final StaticCapableStubber doThrow(Class<out Throwable> toBeThrown, Array<Class<out Throwable>> nextToBeThrown)
-
doAnswer
StaticCapableStubber doAnswer(Answer answer)
-
doNothing
StaticCapableStubber doNothing()
-
doReturn
StaticCapableStubber doReturn(Object toBeReturned)
-
doReturn
StaticCapableStubber doReturn(Object toBeReturned, Array<Object> nextToBeReturned)
-
doCallRealMethod
StaticCapableStubber doCallRealMethod()
-
-
-
-