|
15 | 15 | package com.google.firebase.heartbeatinfo;
|
16 | 16 |
|
17 | 17 | import static com.google.common.truth.Truth.assertThat;
|
18 |
| -import static org.mockito.ArgumentMatchers.anyBoolean; |
19 | 18 | import static org.mockito.ArgumentMatchers.anyLong;
|
20 | 19 | import static org.mockito.ArgumentMatchers.anyString;
|
21 | 20 | import static org.mockito.Mockito.mock;
|
22 |
| -import static org.mockito.Mockito.times; |
23 |
| -import static org.mockito.Mockito.verify; |
24 | 21 | import static org.mockito.Mockito.when;
|
25 | 22 |
|
26 |
| -import java.util.ArrayList; |
27 | 23 | import java.util.HashSet;
|
28 | 24 | import java.util.List;
|
29 | 25 | import java.util.Set;
|
30 |
| -import java.util.concurrent.ExecutionException; |
31 | 26 | import java.util.concurrent.ExecutorService;
|
32 | 27 | import java.util.concurrent.LinkedBlockingQueue;
|
33 | 28 | import java.util.concurrent.ThreadPoolExecutor;
|
@@ -67,108 +62,6 @@ public void getHeartBeatCode_noHeartBeat() {
|
67 | 62 | assertThat(heartBeatInfo.getHeartBeatCode(testSdk).getCode()).isEqualTo(0);
|
68 | 63 | }
|
69 | 64 |
|
70 |
| - @Test |
71 |
| - public void whenNoSource_dontStoreHeartBeat() throws ExecutionException, InterruptedException { |
72 |
| - |
73 |
| - DefaultHeartBeatInfo info = new DefaultHeartBeatInfo(() -> storage, new HashSet<>(), executor); |
74 |
| - info.storeHeartBeatInfo(testSdk).addOnCompleteListener(executor, storeOnCompleteListener); |
75 |
| - storeOnCompleteListener.await(); |
76 |
| - verify(storage, times(0)).storeHeartBeatInformation(anyString(), anyLong()); |
77 |
| - } |
78 |
| - |
79 |
| - @Test |
80 |
| - public void storeHeartBeatCode_noHeartBeat() throws ExecutionException, InterruptedException { |
81 |
| - when(storage.shouldSendSdkHeartBeat(anyString(), anyLong())).thenReturn(Boolean.FALSE); |
82 |
| - when(storage.shouldSendGlobalHeartBeat(anyLong())).thenReturn(Boolean.FALSE); |
83 |
| - heartBeatInfo |
84 |
| - .storeHeartBeatInfo(testSdk) |
85 |
| - .addOnCompleteListener(executor, storeOnCompleteListener); |
86 |
| - storeOnCompleteListener.await(); |
87 |
| - heartBeatInfo |
88 |
| - .getAndClearStoredHeartBeatInfo() |
89 |
| - .addOnCompleteListener(executor, getOnCompleteListener); |
90 |
| - List<HeartBeatResult> result = getOnCompleteListener.await(); |
91 |
| - assertThat(result.size()).isEqualTo(0); |
92 |
| - } |
93 |
| - |
94 |
| - @Test |
95 |
| - public void storeHeartBeatCode_sdkButNoGlobalHeartBeat() |
96 |
| - throws ExecutionException, InterruptedException { |
97 |
| - ArrayList<SdkHeartBeatResult> returnResults = new ArrayList<>(); |
98 |
| - returnResults.add(SdkHeartBeatResult.create(testSdk, 1000000001)); |
99 |
| - when(storage.shouldSendSdkHeartBeat(anyString(), anyLong())).thenReturn(Boolean.TRUE); |
100 |
| - when(storage.shouldSendGlobalHeartBeat(anyLong())).thenReturn(Boolean.FALSE); |
101 |
| - when(storage.getLastGlobalHeartBeat()).thenReturn((long) 1000000000); |
102 |
| - when(storage.getStoredHeartBeats(anyBoolean())).thenReturn(returnResults); |
103 |
| - heartBeatInfo |
104 |
| - .storeHeartBeatInfo(testSdk) |
105 |
| - .addOnCompleteListener(executor, storeOnCompleteListener); |
106 |
| - storeOnCompleteListener.await(); |
107 |
| - heartBeatInfo |
108 |
| - .getAndClearStoredHeartBeatInfo() |
109 |
| - .addOnCompleteListener(executor, getOnCompleteListener); |
110 |
| - List<HeartBeatResult> results = getOnCompleteListener.await(); |
111 |
| - verify(storage, times(1)).storeHeartBeatInformation(anyString(), anyLong()); |
112 |
| - assertThat(results.size()).isEqualTo(1); |
113 |
| - assertThat(results.get(0)) |
114 |
| - .isEqualTo(HeartBeatResult.create(testSdk, 1000000001, HeartBeatInfo.HeartBeat.SDK)); |
115 |
| - verify(storage, times(1)).updateGlobalHeartBeat(1000000000); |
116 |
| - } |
117 |
| - |
118 |
| - @Test |
119 |
| - public void storeHeartBeatCode_globalAndSDKHeartBeat() |
120 |
| - throws ExecutionException, InterruptedException { |
121 |
| - ArrayList<SdkHeartBeatResult> returnResults = new ArrayList<>(); |
122 |
| - returnResults.add(SdkHeartBeatResult.create(testSdk, 100000000)); |
123 |
| - when(storage.shouldSendSdkHeartBeat(anyString(), anyLong())).thenReturn(Boolean.TRUE); |
124 |
| - when(storage.shouldSendGlobalHeartBeat(anyLong())).thenReturn(Boolean.TRUE); |
125 |
| - when(storage.getLastGlobalHeartBeat()).thenReturn((long) 0); |
126 |
| - when(storage.getStoredHeartBeats(anyBoolean())).thenReturn(returnResults); |
127 |
| - heartBeatInfo |
128 |
| - .storeHeartBeatInfo(testSdk) |
129 |
| - .addOnCompleteListener(executor, storeOnCompleteListener); |
130 |
| - storeOnCompleteListener.await(); |
131 |
| - heartBeatInfo |
132 |
| - .getAndClearStoredHeartBeatInfo() |
133 |
| - .addOnCompleteListener(executor, getOnCompleteListener); |
134 |
| - List<HeartBeatResult> results = getOnCompleteListener.await(); |
135 |
| - verify(storage, times(1)).storeHeartBeatInformation(anyString(), anyLong()); |
136 |
| - assertThat(results.size()).isEqualTo(1); |
137 |
| - assertThat(results.get(0)) |
138 |
| - .isEqualTo(HeartBeatResult.create(testSdk, 100000000, HeartBeatInfo.HeartBeat.COMBINED)); |
139 |
| - verify(storage, times(1)).updateGlobalHeartBeat(100000000); |
140 |
| - } |
141 |
| - |
142 |
| - @Test |
143 |
| - public void storeHeartBeatCode_ThreeHeartBeats() throws ExecutionException, InterruptedException { |
144 |
| - ArrayList<SdkHeartBeatResult> returnResults = new ArrayList<>(); |
145 |
| - returnResults.add(SdkHeartBeatResult.create(testSdk, 100000000)); |
146 |
| - returnResults.add(SdkHeartBeatResult.create(testSdk, 200000000)); |
147 |
| - returnResults.add(SdkHeartBeatResult.create(testSdk, 200002000)); |
148 |
| - when(storage.shouldSendSdkHeartBeat(anyString(), anyLong())).thenReturn(Boolean.TRUE); |
149 |
| - when(storage.shouldSendGlobalHeartBeat(anyLong())).thenReturn(Boolean.TRUE); |
150 |
| - when(storage.getLastGlobalHeartBeat()).thenReturn((long) 0); |
151 |
| - when(storage.getStoredHeartBeats(anyBoolean())).thenReturn(returnResults); |
152 |
| - |
153 |
| - heartBeatInfo |
154 |
| - .storeHeartBeatInfo(testSdk) |
155 |
| - .addOnCompleteListener(executor, storeOnCompleteListener); |
156 |
| - storeOnCompleteListener.await(); |
157 |
| - heartBeatInfo |
158 |
| - .getAndClearStoredHeartBeatInfo() |
159 |
| - .addOnCompleteListener(executor, getOnCompleteListener); |
160 |
| - List<HeartBeatResult> results = getOnCompleteListener.await(); |
161 |
| - verify(storage, times(1)).storeHeartBeatInformation(anyString(), anyLong()); |
162 |
| - assertThat(results.size()).isEqualTo(3); |
163 |
| - assertThat(results.get(0)) |
164 |
| - .isEqualTo(HeartBeatResult.create(testSdk, 100000000, HeartBeatInfo.HeartBeat.COMBINED)); |
165 |
| - assertThat(results.get(1)) |
166 |
| - .isEqualTo(HeartBeatResult.create(testSdk, 200000000, HeartBeatInfo.HeartBeat.COMBINED)); |
167 |
| - assertThat(results.get(2)) |
168 |
| - .isEqualTo(HeartBeatResult.create(testSdk, 200002000, HeartBeatInfo.HeartBeat.SDK)); |
169 |
| - verify(storage, times(1)).updateGlobalHeartBeat(200000000); |
170 |
| - } |
171 |
| - |
172 | 65 | @Test
|
173 | 66 | public void getHeartBeatCode_sdkHeartBeat() {
|
174 | 67 | when(storage.shouldSendSdkHeartBeat(anyString(), anyLong())).thenReturn(Boolean.TRUE);
|
|
0 commit comments