1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito; 6 7 import org.mockito.verification.VerificationMode; 8 9 /** 10 * Allows verification in order. E.g: 11 * 12 * <pre class="code"><code class="java"> 13 * InOrder inOrder = inOrder(firstMock, secondMock); 14 * 15 * inOrder.verify(firstMock).add("was called first"); 16 * inOrder.verify(secondMock).add("was called second"); 17 * </code></pre> 18 * 19 * As of Mockito 1.8.4 you can verifyNoMoreInteractions() in order-sensitive way. Read more: {@link InOrder#verifyNoMoreInteractions()} 20 * <p> 21 * 22 * See examples in javadoc for {@link Mockito} class 23 */ 24 public interface InOrder { 25 /** 26 * Verifies interaction <b>happened once</b> in order. 27 * <p> 28 * Alias to <code>inOrder.verify(mock, times(1))</code> 29 * <p> 30 * Example: 31 * <pre class="code"><code class="java"> 32 * InOrder inOrder = inOrder(firstMock, secondMock); 33 * 34 * inOrder.verify(firstMock).someMethod("was called first"); 35 * inOrder.verify(secondMock).someMethod("was called second"); 36 * </code></pre> 37 * 38 * See examples in javadoc for {@link Mockito} class 39 * 40 * @param mock to be verified 41 * 42 * @return mock object itself 43 */ verify(T mock)44 <T> T verify(T mock); 45 46 /** 47 * Verifies interaction in order. E.g: 48 * 49 * <pre class="code"><code class="java"> 50 * InOrder inOrder = inOrder(firstMock, secondMock); 51 * 52 * inOrder.verify(firstMock, times(2)).someMethod("was called first two times"); 53 * inOrder.verify(secondMock, atLeastOnce()).someMethod("was called second at least once"); 54 * </code></pre> 55 * 56 * See examples in javadoc for {@link Mockito} class 57 * 58 * @param mock to be verified 59 * @param mode for example times(x) or atLeastOnce() 60 * 61 * @return mock object itself 62 */ verify(T mock, VerificationMode mode)63 <T> T verify(T mock, VerificationMode mode); 64 65 /** 66 * Verifies that no more interactions happened <b>in order</b>. 67 * Different from {@link Mockito#verifyNoMoreInteractions(Object...)} because the order of verification matters. 68 * <p> 69 * Example: 70 * <pre class="code"><code class="java"> 71 * mock.foo(); //1st 72 * mock.bar(); //2nd 73 * mock.baz(); //3rd 74 * 75 * InOrder inOrder = inOrder(mock); 76 * 77 * inOrder.verify(mock).bar(); //2n 78 * inOrder.verify(mock).baz(); //3rd (last method) 79 * 80 * //passes because there are no more interactions after last method: 81 * inOrder.verifyNoMoreInteractions(); 82 * 83 * //however this fails because 1st method was not verified: 84 * Mockito.verifyNoMoreInteractions(mock); 85 * </code></pre> 86 */ verifyNoMoreInteractions()87 void verifyNoMoreInteractions(); 88 } 89