use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManagerTest method initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingDisabled.
@Test
public void initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingDisabled() {
boolean downloadToCache = true;
boolean updateConfigOnNewDatafile = false;
// disable polling
int pollingInterval = 0;
DefaultDatafileHandler datafileHandler = spy(new DefaultDatafileHandler());
Logger logger = mock(Logger.class);
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0, null, null, null, null, null);
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
String newDatafile = manager.getDatafile(context, R.raw.datafile_api);
datafileHandler.saveDatafile(context, manager.getDatafileConfig(), newDatafile);
return null;
}
}).when(manager.getDatafileHandler()).downloadDatafile(any(Context.class), any(DatafileConfig.class), any(DatafileLoadedListener.class));
OptimizelyClient client = manager.initialize(context, defaultDatafile, downloadToCache, updateConfigOnNewDatafile);
try {
executor.awaitTermination(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
//
}
// when periodic polling enabled, project config always updated on cache datafile update (regardless of "updateConfigOnNewDatafile" setting)
// wait for first download.
assertEquals(client.getOptimizelyConfig().getRevision(), "7");
}
Aggregations