|
| 1 | +/**************************************************************************** |
| 2 | + * Copyright 2017, Optimizely, Inc. and contributors * |
| 3 | + * * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * |
| 5 | + * you may not use this file except in compliance with the License. * |
| 6 | + * You may obtain a copy of the License at * |
| 7 | + * * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * |
| 9 | + * * |
| 10 | + * Unless required by applicable law or agreed to in writing, software * |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * |
| 13 | + * See the License for the specific language governing permissions and * |
| 14 | + * limitations under the License. * |
| 15 | + ***************************************************************************/ |
| 16 | + |
| 17 | +package com.optimizely.ab.android.sdk; |
| 18 | + |
| 19 | +import android.app.UiModeManager; |
| 20 | +import android.content.Context; |
| 21 | +import android.content.res.Configuration; |
| 22 | +import android.os.Build; |
| 23 | +import android.support.annotation.RequiresApi; |
| 24 | +import android.support.test.InstrumentationRegistry; |
| 25 | +import android.support.test.espresso.core.deps.guava.util.concurrent.ListeningExecutorService; |
| 26 | +import android.support.test.runner.AndroidJUnit4; |
| 27 | + |
| 28 | +import com.optimizely.ab.Optimizely; |
| 29 | +import com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler; |
| 30 | +import com.optimizely.ab.android.event_handler.DefaultEventHandler; |
| 31 | +import com.optimizely.ab.android.user_profile.DefaultUserProfileService; |
| 32 | +import com.optimizely.ab.config.Experiment; |
| 33 | +import com.optimizely.ab.config.ProjectConfig; |
| 34 | +import com.optimizely.ab.config.Variation; |
| 35 | +import com.optimizely.ab.event.internal.payload.Event; |
| 36 | +import com.optimizely.ab.notification.NotificationListener; |
| 37 | + |
| 38 | +import org.junit.Assert; |
| 39 | +import org.junit.Before; |
| 40 | +import org.junit.Test; |
| 41 | +import org.junit.runner.RunWith; |
| 42 | +import org.mockito.Mock; |
| 43 | +import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent; |
| 44 | +import org.slf4j.Logger; |
| 45 | +import org.slf4j.LoggerFactory; |
| 46 | + |
| 47 | +import java.util.Collections; |
| 48 | +import java.util.HashMap; |
| 49 | +import java.util.Map; |
| 50 | + |
| 51 | +import static junit.framework.Assert.assertEquals; |
| 52 | +import static junit.framework.Assert.assertFalse; |
| 53 | +import static junit.framework.Assert.assertNotNull; |
| 54 | +import static junit.framework.Assert.assertNull; |
| 55 | +import static junit.framework.Assert.assertTrue; |
| 56 | +import static org.mockito.Mockito.mock; |
| 57 | +import static org.mockito.Mockito.verify; |
| 58 | +import static org.mockito.Mockito.verifyZeroInteractions; |
| 59 | +import static org.mockito.Mockito.when; |
| 60 | + |
| 61 | +@RunWith(AndroidJUnit4.class) |
| 62 | +public class OptimizelyManagerBuilderTest { |
| 63 | + private Logger logger = mock(Logger.class); |
| 64 | + |
| 65 | + private String testProjectId = "7595190003"; |
| 66 | + |
| 67 | + private String minDatafile = "{\"groups\": [], \"projectId\": \"8504447126\", \"variables\": [{\"defaultValue\": \"true\", \"type\": \"boolean\", \"id\": \"8516291943\", \"key\": \"test_variable\"}], \"version\": \"3\", \"experiments\": [{\"status\": \"Running\", \"key\": \"android_experiment_key\", \"layerId\": \"8499056327\", \"trafficAllocation\": [{\"entityId\": \"8509854340\", \"endOfRange\": 5000}, {\"entityId\": \"8505434669\", \"endOfRange\": 10000}], \"audienceIds\": [], \"variations\": [{\"variables\": [], \"id\": \"8509854340\", \"key\": \"var_1\"}, {\"variables\": [], \"id\": \"8505434669\", \"key\": \"var_2\"}], \"forcedVariations\": {}, \"id\": \"8509139139\"}], \"audiences\": [], \"anonymizeIP\": true, \"attributes\": [], \"revision\": \"7\", \"events\": [{\"experimentIds\": [\"8509139139\"], \"id\": \"8505434668\", \"key\": \"test_event\"}], \"accountId\": \"8362480420\"}"; |
| 68 | + |
| 69 | + @Before |
| 70 | + public void setUp() throws Exception { |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testBuilderWith() { |
| 75 | + OptimizelyManager manager = OptimizelyManager.builder(testProjectId).withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getTargetContext())) |
| 76 | + .withDatafileDownloadInterval(30L) |
| 77 | + .withEventDispatchInterval(30L) |
| 78 | + .withDatafileHandler(new DefaultDatafileHandler()) |
| 79 | + .withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getTargetContext())) |
| 80 | + .withLogger(logger).build(InstrumentationRegistry.getTargetContext()); |
| 81 | + |
| 82 | + assertNotNull(manager); |
| 83 | + assertNotNull(manager.getDatafileHandler()); |
| 84 | + assertNotNull(manager.getUserProfileService()); |
| 85 | + assertNotNull(manager.getEventHandler(InstrumentationRegistry.getTargetContext())); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + public void testBuilderWithOut() { |
| 90 | + OptimizelyManager manager = OptimizelyManager.builder(testProjectId).build(InstrumentationRegistry.getTargetContext()); |
| 91 | + |
| 92 | + assertNotNull(manager); |
| 93 | + assertNotNull(manager.getDatafileHandler()); |
| 94 | + assertNotNull(manager.getUserProfileService()); |
| 95 | + assertNotNull(manager.getEventHandler(InstrumentationRegistry.getTargetContext())); |
| 96 | + } |
| 97 | + |
| 98 | +} |
0 commit comments