16
16
17
17
package com .optimizely .ab .android .sdk ;
18
18
19
+ import static org .mockito .Matchers .any ;
20
+ import static org .mockito .Matchers .anyInt ;
21
+ import static org .mockito .Matchers .anyList ;
22
+ import static org .mockito .Matchers .anyLong ;
23
+ import static org .mockito .Matchers .anyString ;
24
+ import static org .mockito .Matchers .eq ;
25
+ import static org .mockito .Mockito .mock ;
26
+ import static org .mockito .Mockito .verify ;
27
+ import static org .mockito .Mockito .when ;
28
+ import static org .powermock .api .mockito .PowerMockito .mockStatic ;
29
+ import static org .powermock .api .mockito .PowerMockito .verifyNew ;
30
+ import static org .powermock .api .mockito .PowerMockito .whenNew ;
31
+
19
32
import android .content .Context ;
20
33
21
34
import com .optimizely .ab .android .datafile_handler .DatafileHandler ;
22
35
import com .optimizely .ab .android .event_handler .DefaultEventHandler ;
23
36
import com .optimizely .ab .android .shared .DatafileConfig ;
24
- import com .optimizely .ab .android .user_profile .DefaultUserProfileService ;
25
37
import com .optimizely .ab .bucketing .UserProfileService ;
26
38
import com .optimizely .ab .error .ErrorHandler ;
27
39
import com .optimizely .ab .event .BatchEventProcessor ;
32
44
import org .junit .Before ;
33
45
import org .junit .Test ;
34
46
import org .junit .runner .RunWith ;
35
- import org .mockito .runners .MockitoJUnitRunner ;
36
- import org .powermock .api .mockito .PowerMockito ;
47
+ import org .powermock .core .PowerMockUtils ;
37
48
import org .powermock .core .classloader .annotations .PowerMockIgnore ;
38
49
import org .powermock .core .classloader .annotations .PrepareForTest ;
39
50
import org .powermock .modules .junit4 .PowerMockRunner ;
51
+
40
52
import org .slf4j .Logger ;
41
53
42
- import java .util .List ;
43
54
import java .util .concurrent .BlockingQueue ;
44
55
import java .util .concurrent .ExecutorService ;
45
56
import java .util .concurrent .TimeUnit ;
46
57
47
- import static junit .framework .Assert .assertEquals ;
48
- import static junit .framework .Assert .assertFalse ;
49
- import static org .mockito .Matchers .any ;
50
- import static org .mockito .Matchers .anyBoolean ;
51
- import static org .mockito .Matchers .anyList ;
52
- import static org .mockito .Matchers .anyLong ;
53
- import static org .mockito .Matchers .anyInt ;
54
- import static org .mockito .Matchers .anyObject ;
55
- import static org .mockito .Matchers .anyString ;
56
- import static org .mockito .Matchers .eq ;
57
- import static org .mockito .Mockito .mock ;
58
- import static org .mockito .Mockito .never ;
59
- import static org .mockito .Mockito .verify ;
60
- import static org .mockito .Mockito .when ;
61
- import static org .powermock .api .mockito .PowerMockito .mockStatic ;
62
- import static org .powermock .api .mockito .PowerMockito .verifyNew ;
63
- import static org .powermock .api .mockito .PowerMockito .whenNew ;
64
-
65
58
66
59
@ RunWith (PowerMockRunner .class )
67
60
@ PowerMockIgnore ("jdk.internal.reflect.*" )
@@ -75,7 +68,6 @@ public class OptimizelyManagerIntervalTest {
75
68
@ Before
76
69
public void setup () throws Exception {
77
70
mockContext = mock (Context .class );
78
- when (mockContext .getApplicationContext ()).thenReturn (mockContext );
79
71
80
72
whenNew (OptimizelyManager .class ).withAnyArguments ().thenReturn (mock (OptimizelyManager .class ));
81
73
whenNew (BatchEventProcessor .class ).withAnyArguments ().thenReturn (mock (BatchEventProcessor .class ));
@@ -95,19 +87,20 @@ public void testBuildWithDatafileDownloadInterval() throws Exception {
95
87
.withDatafileDownloadInterval (goodNumber , TimeUnit .MINUTES )
96
88
.build (mockContext );
97
89
98
- verifyNew (OptimizelyManager .class ).withArguments (anyString (),
90
+ verifyNew (OptimizelyManager .class ).withArguments (
99
91
anyString (),
92
+ any (), // nullable (String)
100
93
any (DatafileConfig .class ),
101
94
any (Logger .class ),
102
95
eq (goodNumber * 60L ), // seconds
103
96
any (DatafileHandler .class ),
104
- any (ErrorHandler . class ),
97
+ any (), // nullable (ErrorHandler)
105
98
anyLong (),
106
99
any (EventHandler .class ),
107
100
any (EventProcessor .class ),
108
101
any (UserProfileService .class ),
109
102
any (NotificationCenter .class ),
110
- anyList ());
103
+ any ()); // nullable (DefaultDecideOptions)
111
104
}
112
105
113
106
@ Test
@@ -118,19 +111,20 @@ public void testBuildWithDatafileDownloadIntervalDeprecated() throws Exception {
118
111
.withDatafileDownloadInterval (goodNumber ) // deprecated
119
112
.build (mockContext );
120
113
121
- verifyNew (OptimizelyManager .class ).withArguments (anyString (),
114
+ verifyNew (OptimizelyManager .class ).withArguments (
122
115
anyString (),
116
+ any (), // nullable (String)
123
117
any (DatafileConfig .class ),
124
118
any (Logger .class ),
125
- eq (goodNumber ), // seconds
119
+ eq (goodNumber ), // seconds
126
120
any (DatafileHandler .class ),
127
- any (ErrorHandler . class ),
121
+ any (), // nullable (ErrorHandler)
128
122
anyLong (),
129
123
any (EventHandler .class ),
130
124
any (EventProcessor .class ),
131
125
any (UserProfileService .class ),
132
126
any (NotificationCenter .class ),
133
- anyList ());
127
+ any ()); // nullable (DefaultDecideOptions)
134
128
}
135
129
136
130
@ Test
@@ -141,30 +135,32 @@ public void testBuildWithEventDispatchInterval() throws Exception {
141
135
.withEventDispatchInterval (goodNumber , TimeUnit .SECONDS )
142
136
.build (mockContext );
143
137
144
- verifyNew (BatchEventProcessor .class ).withArguments (any (BlockingQueue .class ),
138
+ verifyNew (BatchEventProcessor .class ).withArguments (
139
+ any (BlockingQueue .class ),
145
140
any (EventHandler .class ),
146
141
anyInt (),
147
142
eq (goodNumber * 1000L ), // milliseconds
148
143
anyLong (),
149
144
any (ExecutorService .class ),
150
145
any (NotificationCenter .class ),
151
- any (Object . class ));
146
+ any ()); // PowerMock bug? requires an extra null at the end
152
147
153
148
verify (mockEventHandler ).setDispatchInterval (-1L ); // default
154
149
155
- verifyNew (OptimizelyManager .class ).withArguments (anyString (),
150
+ verifyNew (OptimizelyManager .class ).withArguments (
156
151
anyString (),
152
+ any (), // nullable (String)
157
153
any (DatafileConfig .class ),
158
154
any (Logger .class ),
159
155
anyLong (),
160
156
any (DatafileHandler .class ),
161
- any (ErrorHandler . class ),
157
+ any (), // nullable (ErrorHandler)
162
158
eq (-1L ), // default
163
159
any (EventHandler .class ),
164
160
any (EventProcessor .class ),
165
161
any (UserProfileService .class ),
166
162
any (NotificationCenter .class ),
167
- anyList ());
163
+ any ()); // nullable (DefaultDecideOptions)
168
164
}
169
165
170
166
@ Test
@@ -178,30 +174,32 @@ public void testBuildWithEventDispatchRetryInterval() throws Exception {
178
174
.withEventDispatchRetryInterval (goodNumber , timeUnit )
179
175
.build (mockContext );
180
176
181
- verifyNew (BatchEventProcessor .class ).withArguments (any (BlockingQueue .class ),
177
+ verifyNew (BatchEventProcessor .class ).withArguments (
178
+ any (BlockingQueue .class ),
182
179
any (EventHandler .class ),
183
180
anyInt (),
184
181
eq (defaultEventFlushInterval * 1000L ), // milliseconds
185
182
anyLong (),
186
183
any (ExecutorService .class ),
187
184
any (NotificationCenter .class ),
188
- any (Object . class ));
185
+ any ()); // PowerMock bug? requires an extra null at the end
189
186
190
187
verify (mockEventHandler ).setDispatchInterval (timeUnit .toMillis (goodNumber )); // milli-seconds
191
188
192
- verifyNew (OptimizelyManager .class ).withArguments (anyString (),
189
+ verifyNew (OptimizelyManager .class ).withArguments (
193
190
anyString (),
191
+ any (), // nullable (String)
194
192
any (DatafileConfig .class ),
195
193
any (Logger .class ),
196
194
anyLong (),
197
195
any (DatafileHandler .class ),
198
- any (ErrorHandler . class ),
196
+ any (), // nullable (ErrorHandler)
199
197
eq (goodNumber * 1000L * 60L ), // milliseconds
200
198
any (EventHandler .class ),
201
199
any (EventProcessor .class ),
202
200
any (UserProfileService .class ),
203
201
any (NotificationCenter .class ),
204
- anyList ());
202
+ any ()); // nullable (DefaultDecideOptions)
205
203
}
206
204
207
205
@ Test
@@ -219,23 +217,24 @@ public void testBuildWithEventDispatchIntervalDeprecated() throws Exception {
219
217
anyLong (),
220
218
any (ExecutorService .class ),
221
219
any (NotificationCenter .class ),
222
- any (Object . class ));
220
+ any ()); // PowerMock bug? requires an extra null at the end
223
221
224
222
verify (mockEventHandler ).setDispatchInterval (-1L ); // deprecated api not change default retryInterval
225
223
226
- verifyNew (OptimizelyManager .class ).withArguments (anyString (),
224
+ verifyNew (OptimizelyManager .class ).withArguments (
227
225
anyString (),
226
+ any (), // nullable (String)
228
227
any (DatafileConfig .class ),
229
228
any (Logger .class ),
230
229
anyLong (),
231
230
any (DatafileHandler .class ),
232
- any (ErrorHandler . class ),
231
+ any (), // nullable (ErrorHandler)
233
232
eq (-1L ), // deprecated api not change default retryInterval
234
233
any (EventHandler .class ),
235
234
any (EventProcessor .class ),
236
235
any (UserProfileService .class ),
237
236
any (NotificationCenter .class ),
238
- anyList ());
237
+ any ()); // nullable (DefaultDecideOptions)
239
238
}
240
239
241
240
}
0 commit comments