Java 类org.robolectric.util.concurrent.RoboExecutorService 实例源码

项目:annotated-mvp    文件:PresenterUnitTestCase.java   
private void findAndSetFields() throws IllegalAccessException, NoSuchFieldException
{
    Field[] fields = getClass().getDeclaredFields();
    for (Field field : fields)
    {
        if (field.getAnnotation(InjectMocks.class) != null){
            field.setAccessible(true);
            Object obj = field.get(this);
            if (MvpPresenter.class.isAssignableFrom(obj.getClass())){
                findAndSetField(obj, "executorService", new RoboExecutorService());
                findAndSetField(obj, "handler", new Handler(Looper.myLooper()));
                findAndSetField(obj, "eventBus", eventBus);
            }
        }
    }
}
项目:algoliasearch-client-android    文件:OfflineTestBase.java   
@Override
public void setUp() throws Exception {
    super.setUp();

    client = new OfflineClient(RuntimeEnvironment.application, Helpers.app_id, Helpers.api_key);
    // NOTE: We don't really control the package name with Robolectric's supplied application.
    // The license below is generated for package "com.algolia.search.saas.android".
    client.enableOfflineMode("AkcFAQH/pIS5Bf+zpLUFZBhBbGdvbGlhIERldmVsb3BtZW50IFRlYW0fY29tLmFsZ29saWEuc2VhcmNoLnNhYXMuYW5kcm9pZDAtAhR5PKPCETwiBwN+FnUsMtDHwnIlngIVAKY1bFra5zh0fMscmoJ71RA6L3aQ");

    // WARNING: Robolectric cannot work with custom executors in `AsyncTask`, so we substitute the client's
    // executor with a Robolectric-compliant one.
    Whitebox.setInternalState(client, "searchExecutorService", new RoboExecutorService());
    Whitebox.setInternalState(client, "localBuildExecutorService", new RoboExecutorService());
    Whitebox.setInternalState(client, "localSearchExecutorService", new RoboExecutorService());
    Whitebox.setInternalState(client, "transactionExecutorService", new RoboExecutorService());

    // Log the local directory used by Robolectric. Useful when debugging.
    Log.v(this.getClass().getName(), "Robolectric files dir: " + RuntimeEnvironment.application.getFilesDir().getAbsolutePath());
}
项目:algoliasearch-client-android    文件:BrowseIteratorTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    client = new Client(Helpers.app_id, Helpers.api_key);
    // WARNING: Robolectric cannot work with custom executors in `AsyncTask`, so we substitute the client's
    // executor with a Robolectric-compliant one.
    Whitebox.setInternalState(client, "searchExecutorService", new RoboExecutorService());
    indexName = Helpers.safeIndexName("àlgol?à-android");
    index = client.initIndex(indexName);

    objects = new ArrayList<JSONObject>();
    for (int i = 0; i < 1500; ++i) {
        objects.add(new JSONObject(String.format("{\"dummy\": %d}", i)));
    }
    JSONObject task = index.addObjects(new JSONArray(objects), /* requestOptions: */ null);
    index.waitTask(task.getString("taskID"));

    JSONArray objectIDs = task.getJSONArray("objectIDs");
    ids = new ArrayList<String>();
    for (int i = 0; i < objectIDs.length(); ++i) {
        ids.add(objectIDs.getString(i));
    }
}
项目:circleflow-android    文件:FlowSchedulingServiceImplTest.java   
@Test
public void testAsyncJob() {
    FlowSchedulingServiceImpl service = new FlowSchedulingServiceImpl();
    service.setExecutorService(new RoboExecutorService());
    final CallbackVerify callback = new CallbackVerify();
    service.executeAsyncJob(new Runnable() {
        @Override
        public void run() {
            callback.call();
        }
    });
    Assert.assertTrue(callback.isCalled());
}
项目:circleflow-android    文件:FlowSchedulingServiceImplTest.java   
@Test
public void testBackgroundJob() {
    FlowSchedulingServiceImpl service = new FlowSchedulingServiceImpl();
    service.setExecutorService(new RoboExecutorService());
    final CallbackVerify callback = new CallbackVerify();
    service.executeBackgroundJob(new Runnable() {
        @Override
        public void run() {
            callback.call();
        }
    });
    Assert.assertTrue(callback.isCalled());
}
项目:edx-app-android    文件:HttpBaseTestCase.java   
@Override
public void setUp() throws Exception {
    server = new MockWebServer();
    server.setDispatcher(new MockResponseDispatcher());
    server.start();

    okHttpClient = new OkHttpClient.Builder()
            .dispatcher(new Dispatcher(new RoboExecutorService()))
            .addInterceptor(new JsonMergePatchInterceptor())
            .addInterceptor(new OnlyIfCachedStrippingInterceptor())
            .build();

    super.setUp();
}
项目:algoliasearch-client-android    文件:ClientTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    client = new Client(Helpers.app_id, Helpers.api_key);
    // WARNING: Robolectric cannot work with custom executors in `AsyncTask`, so we substitute the client's
    // executor with a Robolectric-compliant one.
    Whitebox.setInternalState(client, "searchExecutorService", new RoboExecutorService());
}
项目:algoliasearch-client-android    文件:PlacesClientTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();

    places = new PlacesClient(Helpers.PLACES_APP_ID, Helpers.PLACES_API_KEY);

    // WARNING: Robolectric cannot work with custom executors in `AsyncTask`, so we substitute the client's
    // executor with a Robolectric-compliant one.
    Whitebox.setInternalState(places, "searchExecutorService", new RoboExecutorService());
}
项目:annotated-mvp    文件:PresenterUnitTestCase.java   
@Before
public void setUp() throws Exception {
    eventBus = new MvpEventBus(new Handler(Looper.myLooper()), new RoboExecutorService());
    findAndSetFields();
}
项目:edx-app-android    文件:ShadowSafeAsyncTask.java   
public void __constructor__() {
    realSafeAsyncTask.executor(new RoboExecutorService());
}
项目:algoliasearch-client-android    文件:IndexTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    client = new Client(Helpers.app_id, Helpers.api_key);
    clientWithLongApiKey = new Client(Helpers.app_id, Helpers.getLongApiKey());
    // WARNING: Robolectric cannot work with custom executors in `AsyncTask`, so we substitute the client's
    // executor with a Robolectric-compliant one.
    Whitebox.setInternalState(client, "searchExecutorService", new RoboExecutorService());
    Whitebox.setInternalState(clientWithLongApiKey, "searchExecutorService", new RoboExecutorService());

    if (!didInitIndices) {
        Index originalIndex = client.getIndex(originalIndexName);
        client.deleteIndex(originalIndexName, /* requestOptions: */ null);

        originalObjects = new ArrayList<>();
        originalObjects.add(new JSONObject("{\"city\": \"San Francisco\", \"state\": \"CA\"}"));
        originalObjects.add(new JSONObject("{\"city\": \"San José\", \"state\": \"CA\"}"));

        JSONObject task = originalIndex.addObjects(new JSONArray(originalObjects), /* requestOptions: */ null);
        originalIndex.waitTask(task.getString("taskID"));

        JSONArray objectIDs = task.getJSONArray("objectIDs");
        originalIds = new ArrayList<>();
        for (int i = 0; i < objectIDs.length(); ++i) {
            originalIds.add(objectIDs.getString(i));
        }

        didInitIndices = true;

        for (int i = 0; i < COUNT_TEST_INDICES; i++) {
            final String iterIndexName = originalIndexName + i;
            client.deleteIndex(iterIndexName, /* requestOptions: */ null);
            task = client.copyIndex(originalIndexName, iterIndexName, /* requestOptions: */ null);
        }
        originalIndex.waitTask(task.getString("taskID"));
    }

    ids = new ArrayList<>(originalIds);
    objects = new ArrayList<>(originalObjects);
    indexName = originalIndexName + countIndices++;
    index = client.getIndex(indexName);
    indexWithLongApiKey = clientWithLongApiKey.getIndex("some_index_name");
}