OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 package org.appspot.apprtc.util; | |
12 | |
13 import org.junit.After; | |
14 import org.junit.Before; | |
15 import org.junit.Test; | |
16 import org.junit.runner.RunWith; | |
17 import org.mockito.Mock; | |
18 import org.mockito.MockitoAnnotations; | |
19 import org.robolectric.RobolectricTestRunner; | |
20 import org.robolectric.annotation.Config; | |
21 import org.robolectric.shadows.ShadowLooper; | |
22 | |
23 import static org.mockito.Mockito.times; | |
24 import static org.mockito.Mockito.verify; | |
25 import static org.mockito.Mockito.verifyNoMoreInteractions; | |
26 import static org.robolectric.Robolectric.shadowOf; | |
27 | |
28 @RunWith(RobolectricTestRunner.class) | |
29 @Config(manifest = Config.NONE) | |
30 public class LooperExecutorTest { | |
31 private final static int RUN_TIMES = 10; | |
32 | |
33 @Mock private Runnable mockRunnable; | |
34 private LooperExecutor executor; | |
35 | |
36 @Before | |
37 public void setUp() { | |
38 MockitoAnnotations.initMocks(this); | |
39 executor = new LooperExecutor(); | |
40 } | |
41 | |
42 @After | |
43 public void tearDown() { | |
44 executor.requestStop(); | |
45 ShadowLooper shadowLooper = getShadowLooper(); | |
46 shadowLooper.idle(); | |
47 } | |
48 | |
49 @Test | |
50 public void testExecute() { | |
51 executor.requestStart(); | |
52 ShadowLooper shadowLooper = getShadowLooper(); | |
53 | |
54 for (int i = 0; i < RUN_TIMES; i++) { | |
55 executor.execute(mockRunnable); | |
56 } | |
57 | |
58 verifyNoMoreInteractions(mockRunnable); | |
59 shadowLooper.idle(); | |
magjed_webrtc
2016/05/19 12:17:13
What happens when shadowLooper.idle() is called? A
sakal
2016/05/19 13:04:38
That is correct. Done.
| |
60 verify(mockRunnable, times(RUN_TIMES)).run(); | |
61 } | |
62 | |
63 @Test | |
64 public void testExecuteBeforeStart() { | |
magjed_webrtc
2016/05/19 12:17:13
Comment that calls to execute() before requestStar
sakal
2016/05/19 13:04:38
Done.
| |
65 executor.execute(mockRunnable); | |
66 verifyNoMoreInteractions(mockRunnable); | |
67 | |
68 executor.requestStart(); | |
69 ShadowLooper shadowLooper = getShadowLooper(); | |
70 shadowLooper.idle(); | |
71 | |
72 verifyNoMoreInteractions(mockRunnable); | |
magjed_webrtc
2016/05/19 12:17:13
Isn't enough with one verifyNoMoreInteractions(moc
sakal
2016/05/19 13:04:38
Done.
| |
73 } | |
74 | |
75 @Test | |
76 public void testExecuteAfterStop() { | |
magjed_webrtc
2016/05/19 12:17:13
Comment that calls to execute() after requestStop(
sakal
2016/05/19 13:04:38
Done.
| |
77 executor.requestStart(); | |
78 ShadowLooper shadowLooper = getShadowLooper(); | |
79 executor.requestStop(); | |
80 | |
81 executor.execute(mockRunnable); | |
82 verifyNoMoreInteractions(mockRunnable); | |
83 shadowLooper.idle(); | |
84 | |
85 verifyNoMoreInteractions(mockRunnable); | |
86 } | |
87 | |
88 @Test | |
89 public void testMultipleStarts() { | |
magjed_webrtc
2016/05/19 12:17:13
Comment that extra requestStart() calls are ok and
sakal
2016/05/19 13:04:38
Done.
| |
90 executor.requestStart(); | |
91 testExecute(); | |
92 } | |
93 | |
94 @Test | |
95 public void testMultipleStops() { | |
96 executor.requestStart(); | |
97 executor.requestStop(); | |
98 executor.requestStop(); | |
99 ShadowLooper shadowLooper = getShadowLooper(); | |
100 shadowLooper.idle(); | |
101 } | |
102 | |
103 private ShadowLooper getShadowLooper() { | |
104 return shadowOf(executor.getHandler().getLooper()); | |
105 } | |
106 } | |
OLD | NEW |