use of com.optimizely.ab.android.datafile_handler.DatafileLoadedListener in project android-sdk by optimizely.
the class OptimizelyManagerTest method initializeAsyncWithEnvironment.
@Test
public void initializeAsyncWithEnvironment() {
Logger logger = mock(Logger.class);
DatafileHandler datafileHandler = mock(DefaultDatafileHandler.class);
EventHandler eventHandler = mock(DefaultEventHandler.class);
EventProcessor eventProcessor = mock(EventProcessor.class);
final OptimizelyManager optimizelyManager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, 3600L, datafileHandler, null, 3600L, eventHandler, eventProcessor, null, null, null);
/*
* Scenario#1: when datafile is not Empty
* Scenario#2: when datafile is Empty
*/
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
((DatafileLoadedListener) invocation.getArguments()[2]).onDatafileLoaded(null);
return null;
}
}).when(optimizelyManager.getDatafileHandler()).downloadDatafile(any(Context.class), any(DatafileConfig.class), any(DatafileLoadedListener.class));
OptimizelyStartListener listener = new OptimizelyStartListener() {
@Override
public void onStart(OptimizelyClient optimizely) {
assertNotNull(optimizelyManager.getOptimizely());
assertNotNull(optimizelyManager.getDatafileHandler());
assertNull(optimizelyManager.getOptimizelyStartListener());
}
};
optimizelyManager.initialize(InstrumentationRegistry.getInstrumentation().getContext(), R.raw.datafile, listener);
verify(optimizelyManager.getDatafileHandler()).startBackgroundUpdates(any(Context.class), eq(new DatafileConfig(testProjectId, testSdkKey)), eq(3600L), any(DatafileLoadedListener.class));
assertEquals(optimizelyManager.isDatafileCached(InstrumentationRegistry.getInstrumentation().getTargetContext()), false);
assertEquals(optimizelyManager.getDatafileUrl(), String.format((DatafileConfig.defaultHost + DatafileConfig.environmentUrlSuffix), testSdkKey));
}
use of com.optimizely.ab.android.datafile_handler.DatafileLoadedListener in project android-sdk by optimizely.
the class OptimizelyManagerDatafileServiceConnectionTest method onServiceConnected.
@Test
public void onServiceConnected() {
DatafileService.LocalBinder binder = mock(DatafileService.LocalBinder.class);
DatafileService service = mock(DatafileService.class);
Context context = mock(Context.class);
when(service.getApplicationContext()).thenReturn(context);
when(binder.getService()).thenReturn(service);
when(optimizelyManager.getDatafileConfig()).thenReturn(new DatafileConfig("1", (String) null));
when(optimizelyManager.getDatafileLoadedListener(context, null)).thenReturn(mock(DatafileLoadedListener.class));
ArgumentCaptor<DatafileLoadedListener> captor = ArgumentCaptor.forClass(DatafileLoadedListener.class);
datafileServiceConnection = new DatafileServiceConnection(optimizelyManager.getDatafileConfig(), context, optimizelyManager.getDatafileLoadedListener(context, null));
datafileServiceConnection.onServiceConnected(null, binder);
String sameString = optimizelyManager.getDatafileConfig().getUrl();
verify(service).getDatafile(eq(sameString), any(DatafileLoader.class), any(DatafileLoadedListener.class));
}
Aggregations