The Mockito library enables mock creation, verification and stubbing. This javadoc content is also available on the https://site.mockito.org/ web page. All documentation
| 1804 | * </code></pre> |
| 1805 | */ |
| 1806 | @CheckReturnValue |
| 1807 | @SuppressWarnings("unchecked") |
| 1808 | public class Mockito extends ArgumentMatchers { |
| 1809 | |
| 1810 | static final MockitoCore MOCKITO_CORE = new MockitoCore(); |
| 1811 | |
| 1812 | /** |
| 1813 | * The default <code>Answer</code> of every mock <b>if</b> the mock was not stubbed. |
| 1814 | * |
| 1815 | * Typically, it just returns some empty value. |
| 1816 | * <p> |
| 1817 | * {@link Answer} can be used to define the return values of un-stubbed invocations. |
| 1818 | * <p> |
| 1819 | * This implementation first tries the global configuration and if there is no global configuration then |
| 1820 | * it will use a default answer that returns zeros, empty collections, nulls, etc. |
| 1821 | */ |
| 1822 | public static final Answer<Object> RETURNS_DEFAULTS = Answers.RETURNS_DEFAULTS; |
| 1823 | |
| 1824 | /** |
| 1825 | * Optional <code>Answer</code> to be used with {@link Mockito#mock(Class, Answer)}. |
| 1826 | * <p> |
| 1827 | * {@link Answer} can be used to define the return values of un-stubbed invocations. |
| 1828 | * <p> |
| 1829 | * This implementation can be helpful when working with legacy code. |
| 1830 | * Un-stubbed methods often return null. If your code uses the object returned by an un-stubbed call, |
| 1831 | * you get a NullPointerException. |
| 1832 | * This implementation of Answer <b>returns SmartNull instead of null</b>. |
| 1833 | * <code>SmartNull</code> gives nicer exception messages than NPEs, because it points out the |
| 1834 | * line where the un-stubbed method was called. You just click on the stack trace. |
| 1835 | * <p> |
| 1836 | * <code>ReturnsSmartNulls</code> first tries to return ordinary values (zeros, empty collections, empty string, etc.) |
| 1837 | * then it tries to return SmartNull. If the return type is final then plain <code>null</code> is returned. |
| 1838 | * <p> |
| 1839 | * Example: |
| 1840 | * <pre class="code"><code class="java"> |
| 1841 | * Foo mock = mock(Foo.class, RETURNS_SMART_NULLS); |
| 1842 | * |
| 1843 | * //calling un-stubbed method here: |
| 1844 | * Stuff stuff = mock.getStuff(); |
| 1845 | * |
| 1846 | * //using object returned by un-stubbed call: |
| 1847 | * stuff.doSomething(); |
| 1848 | * |
| 1849 | * //Above doesn't yield NullPointerException this time! |
| 1850 | * //Instead, SmartNullPointerException is thrown. |
| 1851 | * //Exception's cause links to un-stubbed <i>mock.getStuff()</i> - just click on the stack trace. |
| 1852 | * </code></pre> |
| 1853 | */ |
| 1854 | public static final Answer<Object> RETURNS_SMART_NULLS = Answers.RETURNS_SMART_NULLS; |
| 1855 | |
| 1856 | /** |
| 1857 | * Optional <code>Answer</code> to be used with {@link Mockito#mock(Class, Answer)} |
| 1858 | * <p> |
| 1859 | * {@link Answer} can be used to define the return values of un-stubbed invocations. |
| 1860 | * <p> |
| 1861 | * This implementation can be helpful when working with legacy code. |
| 1862 | * <p> |
| 1863 | * ReturnsMocks first tries to return ordinary values (zeros, empty collections, empty string, etc.) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…