private static Stubber stubber() { return MOCKITO_CORE.stubber(Strictness.LENIENT); } }
public Stubber stubber() { return stubber(null); }
/** * Use <code>doThrow()</code> when you want to stub the void method with an exception. * <p> * Stubbing voids requires different approach from {@link Mockito#when(Object)} because the compiler * does not like void methods inside brackets... * <p> * Example: * * <pre class="code"><code class="java"> * doThrow(new RuntimeException()).when(mock).someVoidMethod(); * </code></pre> * * @param toBeThrown to be thrown when the stubbed method is called * @return stubber - to select a method for stubbing */ @CheckReturnValue public static Stubber doThrow(Throwable... toBeThrown) { return MOCKITO_CORE.stubber().doThrow(toBeThrown); }
/** * Use <code>doThrow()</code> when you want to stub the void method with an exception. * <p> * A new exception instance will be created for each method invocation. * <p> * Stubbing voids requires different approach from {@link Mockito#when(Object)} because the compiler * does not like void methods inside brackets... * <p> * Example: * * <pre class="code"><code class="java"> * doThrow(RuntimeException.class).when(mock).someVoidMethod(); * </code></pre> * * @param toBeThrown to be thrown when the stubbed method is called * @return stubber - to select a method for stubbing * @since 2.1.0 */ @CheckReturnValue public static Stubber doThrow(Class<? extends Throwable> toBeThrown) { return MOCKITO_CORE.stubber().doThrow(toBeThrown); }
/** * Same as {@link #doThrow(Class)} but sets consecutive exception classes to be thrown. Remember to use * <code>doThrow()</code> when you want to stub the void method to throw several exception of specified class. * <p> * A new exception instance will be created for each method invocation. * <p> * Stubbing voids requires different approach from {@link Mockito#when(Object)} because the compiler * does not like void methods inside brackets... * <p> * Example: * * <pre class="code"><code class="java"> * doThrow(RuntimeException.class, BigFailure.class).when(mock).someVoidMethod(); * </code></pre> * * @param toBeThrown to be thrown when the stubbed method is called * @param toBeThrownNext next to be thrown when the stubbed method is called * @return stubber - to select a method for stubbing * @since 2.1.0 */ // Additional method helps users of JDK7+ to hide heap pollution / unchecked generics array creation @SuppressWarnings ({"unchecked", "varargs"}) @CheckReturnValue public static Stubber doThrow(Class<? extends Throwable> toBeThrown, Class<? extends Throwable>... toBeThrownNext) { return MOCKITO_CORE.stubber().doThrow(toBeThrown, toBeThrownNext); }
/** * Use <code>doAnswer()</code> when you want to stub a void method with generic {@link Answer}. * <p> * Stubbing voids requires different approach from {@link Mockito#when(Object)} because the compiler does not like void methods inside brackets... * <p> * Example: * * <pre class="code"><code class="java"> * doAnswer(new Answer() { * public Object answer(InvocationOnMock invocation) { * Object[] args = invocation.getArguments(); * Mock mock = invocation.getMock(); * return null; * }}) * .when(mock).someMethod(); * </code></pre> * <p> * See examples in javadoc for {@link Mockito} class * * @param answer to answer when the stubbed method is called * @return stubber - to select a method for stubbing */ @CheckReturnValue public static Stubber doAnswer(Answer answer) { return MOCKITO_CORE.stubber().doAnswer(answer); }
return MOCKITO_CORE.stubber().doNothing();
return MOCKITO_CORE.stubber().doCallRealMethod();
return MOCKITO_CORE.stubber().doReturn(toBeReturned);
@CheckReturnValue public static Stubber doReturn(Object toBeReturned, Object... toBeReturnedNext) { return MOCKITO_CORE.stubber().doReturn(toBeReturned, toBeReturnedNext);