|
17 | 17 | package com.optimizely.ab.android.sdk;
|
18 | 18 |
|
19 | 19 | import com.optimizely.ab.Optimizely;
|
| 20 | +import com.optimizely.ab.config.Experiment; |
| 21 | +import com.optimizely.ab.config.Variation; |
| 22 | +import com.optimizely.ab.notification.NotificationListener; |
20 | 23 |
|
21 | 24 | import org.junit.Test;
|
22 | 25 | import org.junit.runner.RunWith;
|
|
26 | 29 |
|
27 | 30 | import java.util.Collections;
|
28 | 31 | import java.util.HashMap;
|
| 32 | +import java.util.Map; |
29 | 33 |
|
30 | 34 | import static junit.framework.Assert.assertTrue;
|
31 | 35 | import static junit.framework.Assert.assertFalse;
|
@@ -250,4 +254,80 @@ public void testBadGetVariableFloat() {
|
250 | 254 | verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
|
251 | 255 | "for user {}", "test_key", "userId");
|
252 | 256 | }
|
| 257 | + |
| 258 | + //======== Notification listeners ========// |
| 259 | + |
| 260 | + @Test |
| 261 | + public void testGoodAddNotificationListener() { |
| 262 | + OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger); |
| 263 | + NotificationListener listener = new NotificationListener() { |
| 264 | + @Override |
| 265 | + public void onExperimentActivated(Experiment experiment, |
| 266 | + String s, |
| 267 | + Map<String, String> map, |
| 268 | + Variation variation) { |
| 269 | + } |
| 270 | + }; |
| 271 | + optimizelyClient.addNotificationListener(listener); |
| 272 | + verify(optimizely).addNotificationListener(listener); |
| 273 | + } |
| 274 | + |
| 275 | + @Test |
| 276 | + public void testBadAddNotificationListener() { |
| 277 | + OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger); |
| 278 | + NotificationListener listener = new NotificationListener() { |
| 279 | + @Override |
| 280 | + public void onExperimentActivated(Experiment experiment, |
| 281 | + String s, |
| 282 | + Map<String, String> map, |
| 283 | + Variation variation) { |
| 284 | + } |
| 285 | + }; |
| 286 | + optimizelyClient.addNotificationListener(listener); |
| 287 | + verify(logger).warn("Optimizely is not initialized, could not add notification listener"); |
| 288 | + } |
| 289 | + |
| 290 | + @Test |
| 291 | + public void testGoodRemoveNotificationListener() { |
| 292 | + OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger); |
| 293 | + NotificationListener listener = new NotificationListener() { |
| 294 | + @Override |
| 295 | + public void onExperimentActivated(Experiment experiment, |
| 296 | + String s, |
| 297 | + Map<String, String> map, |
| 298 | + Variation variation) { |
| 299 | + } |
| 300 | + }; |
| 301 | + optimizelyClient.removeNotificationListener(listener); |
| 302 | + verify(optimizely).removeNotificationListener(listener); |
| 303 | + } |
| 304 | + |
| 305 | + @Test |
| 306 | + public void testBadRemoveNotificationListener() { |
| 307 | + OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger); |
| 308 | + NotificationListener listener = new NotificationListener() { |
| 309 | + @Override |
| 310 | + public void onExperimentActivated(Experiment experiment, |
| 311 | + String s, |
| 312 | + Map<String, String> map, |
| 313 | + Variation variation) { |
| 314 | + } |
| 315 | + }; |
| 316 | + optimizelyClient.removeNotificationListener(listener); |
| 317 | + verify(logger).warn("Optimizely is not initialized, could not remove notification listener"); |
| 318 | + } |
| 319 | + |
| 320 | + @Test |
| 321 | + public void testGoodClearNotificationListeners() { |
| 322 | + OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger); |
| 323 | + optimizelyClient.clearNotificationListeners(); |
| 324 | + verify(optimizely).clearNotificationListeners(); |
| 325 | + } |
| 326 | + |
| 327 | + @Test |
| 328 | + public void testBadClearNotificationListeners() { |
| 329 | + OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger); |
| 330 | + optimizelyClient.clearNotificationListeners(); |
| 331 | + verify(logger).warn("Optimizely is not initialized, could not clear notification listeners"); |
| 332 | + } |
253 | 333 | }
|
0 commit comments