|
21 | 21 | import com.optimizely.ab.OptimizelyRuntimeException;
|
22 | 22 | import com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler;
|
23 | 23 | import com.optimizely.ab.android.event_handler.DefaultEventHandler;
|
| 24 | +import com.optimizely.ab.android.shared.DatafileConfig; |
24 | 25 | import com.optimizely.ab.android.user_profile.DefaultUserProfileService;
|
25 | 26 | import com.optimizely.ab.error.ErrorHandler;
|
26 | 27 | import org.junit.Before;
|
27 | 28 | import org.junit.Test;
|
28 | 29 | import org.junit.runner.RunWith;
|
29 | 30 | import org.slf4j.Logger;
|
| 31 | + |
| 32 | +import java.util.concurrent.TimeUnit; |
| 33 | + |
30 | 34 | import static junit.framework.Assert.assertNotNull;
|
| 35 | +import static org.junit.Assert.assertNull; |
31 | 36 | import static org.mockito.Mockito.mock;
|
32 | 37 |
|
33 | 38 | @RunWith(AndroidJUnit4.class)
|
@@ -66,6 +71,78 @@ public <T extends OptimizelyRuntimeException> void handleError(T exception) thro
|
66 | 71 | assertNotNull(manager.getEventHandler(InstrumentationRegistry.getInstrumentation().getTargetContext()));
|
67 | 72 | }
|
68 | 73 |
|
| 74 | + @Test |
| 75 | + public void testBuilderWithOutDatafileConfig() { |
| 76 | + ErrorHandler errorHandler = new ErrorHandler() { |
| 77 | + @Override |
| 78 | + public <T extends OptimizelyRuntimeException> void handleError(T exception) throws T { |
| 79 | + logger.error("Inside error handler", exception); |
| 80 | + } |
| 81 | + }; |
| 82 | + |
| 83 | + OptimizelyManager manager = OptimizelyManager.builder().withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getInstrumentation().getTargetContext())) |
| 84 | + .withDatafileDownloadInterval(30L, TimeUnit.MINUTES) |
| 85 | + .withEventDispatchInterval(30L, TimeUnit.MINUTES) |
| 86 | + .withDatafileHandler(new DefaultDatafileHandler()) |
| 87 | + .withErrorHandler(errorHandler) |
| 88 | + .withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getInstrumentation().getTargetContext())) |
| 89 | + .withLogger(logger).build(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
| 90 | + |
| 91 | + assertNull(manager); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void testBuilderWithOutDatafileConfigWithSdkKey() { |
| 96 | + ErrorHandler errorHandler = new ErrorHandler() { |
| 97 | + @Override |
| 98 | + public <T extends OptimizelyRuntimeException> void handleError(T exception) throws T { |
| 99 | + logger.error("Inside error handler", exception); |
| 100 | + } |
| 101 | + }; |
| 102 | + |
| 103 | + OptimizelyManager manager = OptimizelyManager.builder().withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getInstrumentation().getTargetContext())) |
| 104 | + .withDatafileDownloadInterval(30L, TimeUnit.MINUTES) |
| 105 | + .withEventDispatchInterval(30L, TimeUnit.MINUTES) |
| 106 | + .withDatafileHandler(new DefaultDatafileHandler()) |
| 107 | + .withErrorHandler(errorHandler) |
| 108 | + .withSDKKey("sdkKey7") |
| 109 | + .withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getInstrumentation().getTargetContext())) |
| 110 | + .withLogger(logger).build(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
| 111 | + |
| 112 | + assertNotNull(manager); |
| 113 | + assertNotNull(manager.getDatafileHandler()); |
| 114 | + assertNotNull(manager.getUserProfileService()); |
| 115 | + assertNotNull(manager.getEventHandler(InstrumentationRegistry.getInstrumentation().getTargetContext())); |
| 116 | + |
| 117 | + manager.stop(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + public void testBuilderWithDatafileConfig() { |
| 122 | + ErrorHandler errorHandler = new ErrorHandler() { |
| 123 | + @Override |
| 124 | + public <T extends OptimizelyRuntimeException> void handleError(T exception) throws T { |
| 125 | + logger.error("Inside error handler", exception); |
| 126 | + } |
| 127 | + }; |
| 128 | + |
| 129 | + OptimizelyManager manager = OptimizelyManager.builder().withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getInstrumentation().getTargetContext())) |
| 130 | + .withDatafileDownloadInterval(30L, TimeUnit.MINUTES) |
| 131 | + .withEventDispatchInterval(30L, TimeUnit.MINUTES) |
| 132 | + .withDatafileHandler(new DefaultDatafileHandler()) |
| 133 | + .withErrorHandler(errorHandler) |
| 134 | + .withDatafileConfig(new DatafileConfig(null, "sdkKey7")) |
| 135 | + .withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getInstrumentation().getTargetContext())) |
| 136 | + .withLogger(logger).build(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
| 137 | + |
| 138 | + assertNotNull(manager); |
| 139 | + assertNotNull(manager.getDatafileHandler()); |
| 140 | + assertNotNull(manager.getUserProfileService()); |
| 141 | + assertNotNull(manager.getEventHandler(InstrumentationRegistry.getInstrumentation().getTargetContext())); |
| 142 | + |
| 143 | + manager.stop(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
| 144 | + } |
| 145 | + |
69 | 146 | @Test
|
70 | 147 | public void testBuilderWithOut() {
|
71 | 148 | OptimizelyManager manager = OptimizelyManager.builder(testProjectId).build(InstrumentationRegistry.getInstrumentation().getTargetContext());
|
|
0 commit comments