1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5
6package org.mockito.verification;
7
8import org.mockito.Mockito;
9
10/**
11 * VerificationWithTimeout is a {@link VerificationMode} that allows combining existing verification modes with 'timeout'. E.g:
12 *
13 * <pre class="code"><code class="java">
14 * verify(mock, timeout(100).times(5)).foo();
15 *
16 * verify(mock, timeout(100).never()).bar();
17 *
18 * verify(mock, timeout(200).atLeastOnce()).baz();
19 * </code></pre>
20 *
21 * This is similar to {@link VerificationAfterDelay after()} except this assertion will immediately pass if it becomes true at any point,
22 * whereas after() will wait the full period. Assertions which are consistently expected to be initially true and potentially become false
23 * are deprecated below, and after() should be used instead.
24 *
25 * <p>
26 * See examples in javadoc for {@link Mockito#verify(Object, VerificationMode)}
27 */
28public interface VerificationWithTimeout extends VerificationMode {
29
30    /**
31     * Allows verifying exact number of invocations within given timeout
32     * <pre class="code"><code class="java">
33     *   verify(mock, timeout(100).times(2)).someMethod("some arg");
34     * </code></pre>
35     *
36     * See examples in javadoc for {@link Mockito} class
37     *
38     * @param wantedNumberOfInvocations wanted number of invocations
39     *
40     * @return verification mode
41     */
42    VerificationMode times(int wantedNumberOfInvocations);
43
44    /**
45     * Allows at-least-once verification within given timeout. E.g:
46     * <pre class="code"><code class="java">
47     *   verify(mock, timeout(100).atLeastOnce()).someMethod("some arg");
48     * </code></pre>
49     * Alias to atLeast(1)
50     * <p>
51     * See examples in javadoc for {@link Mockito} class
52     *
53     * @return verification mode
54     */
55    VerificationMode atLeastOnce();
56
57    /**
58     * Allows at-least-x verification within given timeout. E.g:
59     * <pre class="code"><code class="java">
60     *   verify(mock, timeout(100).atLeast(3)).someMethod("some arg");
61     * </code></pre>
62     *
63     * See examples in javadoc for {@link Mockito} class
64     *
65     * @param minNumberOfInvocations minimum number of invocations
66     *
67     * @return verification mode
68     */
69    VerificationMode atLeast(int minNumberOfInvocations);
70
71    /**
72     * Allows checking if given method was the only one invoked. E.g:
73     * <pre class="code"><code class="java">
74     *   verify(mock, only()).someMethod();
75     *   //above is a shorthand for following 2 lines of code:
76     *   verify(mock).someMethod();
77     *   verifyNoMoreInteractions(mock);
78     * </code></pre>
79     *
80     * <p>
81     * See also {@link Mockito#verifyNoMoreInteractions(Object...)}
82     * <p>
83     * See examples in javadoc for {@link Mockito} class
84     *
85     * @return verification mode
86     */
87    VerificationMode only();
88}
89