Lines Matching full:stubbing
10 import org.mockito.internal.stubbing.answers.*;
11 import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues;
12 import org.mockito.internal.stubbing.defaultanswers.ReturnsMoreEmptyValues;
15 import org.mockito.stubbing.*;
22 * Mockito library enables mocks creation, verification and stubbing.
32 * <a href="#2">2. How about some stubbing? </a><br/>
35 * <a href="#5">5. Stubbing void methods with exceptions </a><br/>
40 * <a href="#10">10. Stubbing consecutive calls (iterator-style stubbing) </a><br/>
41 * <a href="#11">11. Stubbing with callbacks </a><br/>
94 * <h3 id="2">2. <a class="meaningful_link" href="#stubbing">How about some stubbing?</a></h3>
100 * //stubbing
124 * <li> Stubbing can be overridden: for example common stubbing can go to
126 * Please note that overridding stubbing is a potential code smell that points out too much stubbing</li>
131 * <li> Last stubbing is more important - when you stubbed the same method with
133 * Other words: <b>the order of stubbing matters</b> but it is only meaningful rarely,
134 * e.g. when stubbing exactly the same method calls or sometimes when argument matchers are used, etc.</li>
146 * //stubbing using built-in anyInt() argument matcher
149 * //stubbing using hamcrest (let's say isValid() returns your own hamcrest matcher):
160 * Argument matchers allow flexible verification or stubbing.
178 * E.g: (example shows verification but the same applies to stubbing):
236 * <h3 id="5">5. <a class="meaningful_link" href="#stubbing_with_exceptions">Stubbing void methods with exceptions</a></h3>
247 * Initially, {@link Mockito#stubVoid(Object)} was used for stubbing voids.
380 * <h3 id="10">10. <a class="meaningful_link" href="#stubbing_consecutive_calls">Stubbing consecutive calls</a> (iterator-style stubbing)</h3>
386 * collections. Those offer natural ways of stubbing (e.g. using real
387 * collections). In rare scenarios stubbing consecutive calls could be useful,
402 * //Any consecutive call: prints "foo" as well (last stubbing wins).
406 * Alternative, shorter version of consecutive stubbing:
416 * <h3 id="11">11. <a class="meaningful_link" href="#answer_stubs">Stubbing with callbacks</a></h3>
418 * Allows stubbing with generic {@link Answer} interface.
421 * originally. We recommend using simple stubbing with <code>thenReturn()</code> or
444 * Stubbing voids requires different approach from {@link Mockito#when(Object)} because the compiler does not
447 * {@link Mockito#doThrow(Throwable)} replaces the {@link Mockito#stubVoid(Object)} method for stubbing voids.
467 * but you may prefer to use these methods in place of the alternative with <code>when()</code>, for all of your stubbing calls.
527 * <li>Sometimes it's impossible or impractical to use {@link Mockito#when(Object)} for stubbing spies.
529 * methods for stubbing. Example:
538 * //You have to use doReturn() for stubbing
590 * <b>Warning:</b> it is recommended to use ArgumentCaptor with verification <b>but not</b> with stubbing.
591 * Using ArgumentCaptor with stubbing may decrease test readability because captor is created outside of assert (aka verify or 'then') block.
601 * Custom argument matchers via {@link ArgumentMatcher} are usually better for stubbing.
661 * //at this point the mock forgot any interactions & stubbing
688 * The problem is that current stubbing api with canonical role of <b>when</b> word does not integrate nicely with <b>//given //when //then</b> comments.
689 * It's because stubbing belongs to <b>given</b> component of the test and not to the <b>when</b> component of the test.
829 * Mockito will now allow you to create mocks when stubbing.
845 * Mockito will now allow to ignore stubbing for the sake of verification.
882 * e.g. invocations, stubbing info, etc.
909 * those calls are <strong>not</strong> remembered for verifications, stubbing does not have effect on them, too.
997 * // note that we're stubbing a chain of methods here: getBar().getName()
1042 * // note that we are actually referring to the very last mock in the stubbing chain.
1150 * e.g. invocations, stubbing info, etc.
1287 * <li>Sometimes it's impossible or impractical to use {@link Mockito#when(Object)} for stubbing spies.
1289 * family of methods for stubbing. Example:
1298 * //You have to use doReturn() for stubbing
1340 * //Last stubbing (e.g: toReturn("foo")) determines the behavior for further consecutive calls.
1354 * For stubbing void methods with throwables see: {@link Mockito#doThrow(Throwable)}
1356 * Stubbing can be overridden: for example common stubbing can go to fixture
1358 * Please note that overridding stubbing is a potential code smell that points out too much stubbing.
1363 * Last stubbing is more important - when you stubbed the same method with
1381 * Enables stubbing methods. Use it when you want the mock to return particular value when particular method is called.
1399 * //Last stubbing (e.g: thenReturn("foo")) determines the behavior of further consecutive calls.
1404 * //Alternative, shorter version for consecutive stubbing:
1418 * For stubbing void methods with throwables see: {@link Mockito#doThrow(Throwable)}
1420 * Stubbing can be overridden: for example common stubbing can go to fixture
1422 * Please note that overridding stubbing is a potential code smell that points out too much stubbing.
1427 * Last stubbing is more important - when you stubbed the same method with
1524 * //at this point the mock forgot any interactions & stubbing
1609 * Originally, <code>stubVoid()</code> was used for stubbing void methods with exceptions. E.g:
1615 * //Last stubbing (e.g. toReturn()) determines the behavior for further consecutive calls.
1624 * @deprecated Use {@link Mockito#doThrow(Throwable)} method for stubbing voids
1628 * @return stubbable object that allows stubbing with throwable
1637 * Stubbing voids requires different approach from {@link Mockito#when(Object)} because the compiler does not like void methods inside brackets...
1646 * @return stubber - to select a method for stubbing
1657 * Stubbing voids requires different approach from {@link Mockito#when(Object)} because the compiler does not like void methods inside brackets...
1666 * @return stubber - to select a method for stubbing
1702 * @return stubber - to select a method for stubbing
1712 * Stubbing voids requires different approach from {@link Mockito#when(Object)} because the compiler does not like void methods inside brackets...
1729 * @return stubber - to select a method for stubbing
1740 * <li>Stubbing consecutive calls on a void method:
1771 * @return stubber - to select a method for stubbing
1780 * <b>Beware that {@link Mockito#when(Object)} is always recommended for stubbing because it is argument type-safe
1781 * and more readable</b> (especially when stubbing consecutive calls).
1796 * //You have to use doReturn() for stubbing:
1801 * <li>Overriding a previous exception-stubbing:
1808 * //You have to use doReturn() for stubbing:
1815 * Spying should be sporadic and overriding exception-stubbing is very rare. Not to mention that in general
1816 * overridding stubbing is a potential code smell that points out too much stubbing.
1821 * @return stubber - to select a method for stubbing
1878 * //stubbing mocks: