1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.concurrentmockito; 6 7 import static org.mockito.Mockito.inOrder; 8 import static org.mockito.Mockito.mock; 9 10 import org.junit.Test; 11 import org.mockito.InOrder; 12 import org.mockitoutil.TestBase; 13 14 public class VerificationInOrderFromMultipleThreadsTest extends TestBase { 15 16 @Test shouldVerifyInOrderWhenMultipleThreadsInteractWithMock()17 public void shouldVerifyInOrderWhenMultipleThreadsInteractWithMock() throws Exception { 18 final Foo testInf = mock(Foo.class); 19 20 Thread threadOne = 21 new Thread( 22 new Runnable() { 23 public void run() { 24 testInf.methodOne(); 25 } 26 }); 27 threadOne.start(); 28 threadOne.join(); 29 30 Thread threadTwo = 31 new Thread( 32 new Runnable() { 33 public void run() { 34 testInf.methodTwo(); 35 } 36 }); 37 threadTwo.start(); 38 threadTwo.join(); 39 40 InOrder inOrder = inOrder(testInf); 41 inOrder.verify(testInf).methodOne(); 42 inOrder.verify(testInf).methodTwo(); 43 } 44 45 public interface Foo { methodOne()46 void methodOne(); 47 methodTwo()48 void methodTwo(); 49 } 50 } 51