@Test public void should_override_default_answer_for_spy_beans() { //given final MockitoDoubleConfiguration configuration = configurationParser.parseSpyConfiguration(ANY_NAME, AnyTest.withAnswer()); //when configuration.createMockSettings(mockSettings); //then final InOrder defaultAnswer = Mockito.inOrder(mockSettings); defaultAnswer .verify(mockSettings) .defaultAnswer(argThat(HasDefaultAnswer.hasAnswerOfType(CallsRealMethods.class))); defaultAnswer .verify(mockSettings) .defaultAnswer(argThat(HasDefaultAnswer.hasAnswerOfType(DoesNothing.class))); }
public static OperationTimeout createMockOperationTimeout() { return mock(OperationTimeout.class, new DoesNothing()); }
private ArgumentCaptor<ThriftApiOperation> mockThriftExecution() { return mockThriftExecutionWith(new DoesNothing()); }
public VoidMethodStubbable<T> toReturn() { invocationContainerImpl.addAnswerForVoidMethod(new DoesNothing()); return this; }
public Stubber doNothing() { answers.add(new DoesNothing()); return this; }
/** * Use doNothing() for setting void methods to do nothing. <b>Beware that * void methods on mocks do nothing by default!</b> However, there are rare * situations when doNothing() comes handy: * <p> * 1. Stubbing consecutive calls on a void method: * * <pre> * doNothing().doThrow(new RuntimeException()).when(mock).someVoidMethod(); * * //does nothing the first time: * mock.someVoidMethod(); * * //throws RuntimeException the next time: * mock.someVoidMethod(); * </pre> * * 2. When you spy real objects and you want the void method to do nothing: * * <pre> * List list = new LinkedList(); * List spy = spy(list); * * //let's make clear() do nothing * doNothing().when(spy).clear(); * * spy.add("one"); * * //clear() does nothing, so the list still contains "one" * spy.clear(); * </pre> * <p> * See examples in javadoc for {@link Mockito} class * * @return stubber - to select a method for stubbing */ public static PowerMockitoStubber doNothing() { return POWERMOCKITO_CORE.doAnswer(new DoesNothing()); }
/** * Use doNothing() for setting void methods to do nothing. <b>Beware that void methods on mocks do nothing by default!</b> * However, there are rare situations when doNothing() comes handy: * <p> * 1. Stubbing consecutive calls on a void method: * <pre> * doNothing(). * doThrow(new RuntimeException()) * .when(mock).someVoidMethod(); * * //does nothing the first time: * mock.someVoidMethod(); * * //throws RuntimeException the next time: * mock.someVoidMethod(); * </pre> * * 2. When you spy real objects and you want the void method to do nothing: * <pre> * List list = new LinkedList(); * List spy = spy(list); * * //let's make clear() do nothing * doNothing().when(spy).clear(); * * spy.add("one"); * * //clear() does nothing, so the list still contains "one" * spy.clear(); * </pre> * <p> * See examples in javadoc for {@link Mockito} class * * @return stubber - to select a method for stubbing */ public static Stubber doNothing() { return MOCKITO_CORE.doAnswer(new DoesNothing()); }