Search in sources :

Example 1 with DatafileLoadedListener

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));
}
Also used : Context(android.content.Context) DatafileLoadedListener(com.optimizely.ab.android.datafile_handler.DatafileLoadedListener) EventHandler(com.optimizely.ab.event.EventHandler) DefaultEventHandler(com.optimizely.ab.android.event_handler.DefaultEventHandler) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Logger(org.slf4j.Logger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EventProcessor(com.optimizely.ab.event.EventProcessor) DatafileHandler(com.optimizely.ab.android.datafile_handler.DatafileHandler) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) Test(org.junit.Test)

Example 2 with DatafileLoadedListener

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));
}
Also used : Context(android.content.Context) DatafileLoadedListener(com.optimizely.ab.android.datafile_handler.DatafileLoadedListener) DatafileLoader(com.optimizely.ab.android.datafile_handler.DatafileLoader) DatafileServiceConnection(com.optimizely.ab.android.datafile_handler.DatafileServiceConnection) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) DatafileService(com.optimizely.ab.android.datafile_handler.DatafileService) Test(org.junit.Test)

Aggregations

Context (android.content.Context)2 DatafileLoadedListener (com.optimizely.ab.android.datafile_handler.DatafileLoadedListener)2 DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)2 Test (org.junit.Test)2 DatafileHandler (com.optimizely.ab.android.datafile_handler.DatafileHandler)1 DatafileLoader (com.optimizely.ab.android.datafile_handler.DatafileLoader)1 DatafileService (com.optimizely.ab.android.datafile_handler.DatafileService)1 DatafileServiceConnection (com.optimizely.ab.android.datafile_handler.DatafileServiceConnection)1 DefaultDatafileHandler (com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler)1 DefaultEventHandler (com.optimizely.ab.android.event_handler.DefaultEventHandler)1 EventHandler (com.optimizely.ab.event.EventHandler)1 EventProcessor (com.optimizely.ab.event.EventProcessor)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Logger (org.slf4j.Logger)1