use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class DatafileServiceTest method testBinding.
@Test
@Ignore
public void testBinding() throws TimeoutException {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
Intent intent = new Intent(context, DatafileService.class);
IBinder binder = null;
int it = 0;
while ((binder = mServiceRule.bindService(intent)) == null && it < MAX_ITERATION) {
it++;
}
final Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
Logger logger = mock(Logger.class);
DatafileCache datafileCache = new DatafileCache("1", new Cache(targetContext, logger), logger);
Client client = mock(Client.class);
DatafileClient datafileClient = new DatafileClient(client, logger);
DatafileLoadedListener datafileLoadedListener = mock(DatafileLoadedListener.class);
DatafileService datafileService = ((DatafileService.LocalBinder) binder).getService();
DatafileLoader datafileLoader = new DatafileLoader(targetContext, datafileClient, datafileCache, mock(Logger.class));
datafileService.getDatafile("1", datafileLoader, datafileLoadedListener);
assertTrue(datafileService.isBound());
}
use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class DatafileWorkerTest method testDatafileFetch.
@Test
public void testDatafileFetch() {
DatafileWorker worker = mockDatafileWorker(sdkKey);
worker.datafileLoader = mock(DatafileLoader.class);
ListenableWorker.Result result = worker.doWork();
DatafileConfig datafileConfig = new DatafileConfig(null, sdkKey);
String datafileUrl = datafileConfig.getUrl();
DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(context, logger), logger);
verify(worker.datafileLoader).getDatafile(eq(datafileUrl), eq(datafileCache), eq(null));
// success
assertThat(result, is(ListenableWorker.Result.success()));
}
use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class BackgroundWatchersCacheTest method setup.
@Before
public void setup() {
logger = mock(Logger.class);
cache = new Cache(InstrumentationRegistry.getInstrumentation().getTargetContext(), logger);
backgroundWatchersCache = new BackgroundWatchersCache(cache, logger);
}
use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class BackgroundWatchersCacheTest method testExceptionHandling.
@Test
public void testExceptionHandling() throws IOException {
Cache cache = mock(Cache.class);
BackgroundWatchersCache backgroundWatchersCache = new BackgroundWatchersCache(cache, logger);
// Cause a JSONException to be thrown
when(cache.load(BackgroundWatchersCache.BACKGROUND_WATCHERS_FILE_NAME)).thenReturn("{");
assertFalse(backgroundWatchersCache.setIsWatching(new DatafileConfig("1", null), true));
verify(logger).error(contains("Unable to update watching state for project id"), any(JSONException.class));
assertFalse(backgroundWatchersCache.isWatching(new DatafileConfig("1", null)));
verify(logger).error(contains("Unable check if project id is being watched"), any(JSONException.class));
List<DatafileConfig> watchingProjectIds = backgroundWatchersCache.getWatchingDatafileConfigs();
assertTrue(watchingProjectIds.isEmpty());
verify(logger).error(contains("Unable to get watching project ids"), any(JSONException.class));
}
use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class DatafileCacheTest method setup.
@Before
public void setup() {
logger = mock(Logger.class);
Cache cache = new Cache(InstrumentationRegistry.getInstrumentation().getTargetContext(), logger);
datafileCache = new DatafileCache("1", cache, logger);
}
Aggregations