/** * Use doAnswer() 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> * doAnswer(new Answer() { * public Object answer(InvocationOnMock invocation) { * Object[] args = invocation.getArguments(); * Mock mock = invocation.getMock(); * return null; * } * }).when(mock).someMethod(); * </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 */ public static PowerMockitoStubber doAnswer(Answer<?> answer) { return POWERMOCKITO_CORE.doAnswer(answer); }
/** * Use doThrow() 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> * doThrow(new RuntimeException()).when(mock).someVoidMethod(); * </pre> * * @param toBeThrown * to be thrown when the stubbed method is called * @return stubber - to select a method for stubbing */ public static PowerMockitoStubber doThrow(Throwable toBeThrown) { return POWERMOCKITO_CORE.doAnswer(new ThrowsException(toBeThrown)); }
return POWERMOCKITO_CORE.doAnswer(new DoesNothing());
public static PowerMockitoStubber doReturn(Object toBeReturned, Object... othersToBeReturned) { if (othersToBeReturned != null && othersToBeReturned.length == 0) { return doReturn(toBeReturned); } return POWERMOCKITO_CORE.doAnswer(new ChainReturns(toBeReturned, othersToBeReturned)); } }
return POWERMOCKITO_CORE.doAnswer(new Returns(toBeReturned));
return POWERMOCKITO_CORE.doAnswer(new CallsRealMethods());
public PowerMockitoStubber doThrow(final Throwable toBeThrown) { return doAnswer(new Callable<Stubber>() { @Override public Stubber call() throws Exception { return Mockito.doThrow(toBeThrown); } }); }
public PowerMockitoStubber doAnswer(final Answer answer) { return doAnswer(new Callable<Stubber>() { @Override public Stubber call() throws Exception { return Mockito.doAnswer(answer); } }); }
public PowerMockitoStubber doNothing() { return doAnswer(new Callable<Stubber>() { @Override public Stubber call() throws Exception { return Mockito.doNothing(); } }); }
public PowerMockitoStubber doReturn(final Object toBeReturned) { return doAnswer(new Callable<Stubber>() { @Override public Stubber call() throws Exception { return Mockito.doReturn(toBeReturned); } }); }
public PowerMockitoStubber doCallRealMethod() { return doAnswer(new Callable<Stubber>() { @Override public Stubber call() throws Exception { return Mockito.doCallRealMethod(); } }); }
public PowerMockitoStubber doAnswer(final Object toBeReturned, final Object... othersToBeReturned) { return doAnswer(new Callable<Stubber>() { @Override public Stubber call() throws Exception { return Mockito.doReturn(toBeReturned, othersToBeReturned); } }); }
/** * Use doAnswer() when you want to stub a void method with generic * {@link Answer}. * <p> * Stubbing voids requires different approach from * {@link PowerMockito#when(Object)} because the compiler does not like void * methods inside brackets... * <p> * Example: * <p> * <pre> * doAnswer(new Answer() { * public Object answer(InvocationOnMock invocation) { * Object[] args = invocation.getArguments(); * Mock mock = invocation.getMock(); * return null; * } * }).when(mock).someMethod(); * </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 */ public static PowerMockitoStubber doAnswer(Answer<?> answer) { return POWERMOCKITO_CORE.doAnswer(answer); }
return POWERMOCKITO_CORE.doAnswer(toBeReturned, othersToBeReturned);