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