org.robolectric.android.util.concurrent.RoboExecutorService Java Examples

The following examples show how to use org.robolectric.android.util.concurrent.RoboExecutorService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OfflineTestBase.java    From algoliasearch-client-android with MIT License 6 votes vote down vote up
@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());
}
 
Example #2
Source File: BrowseIteratorTest.java    From algoliasearch-client-android with MIT License 6 votes vote down vote up
@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));
    }
}
 
Example #3
Source File: HttpBaseTestCase.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@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 OnlyIfCachedStrippingInterceptor())
            .build();

    super.setUp();
}
 
Example #4
Source File: ClientTest.java    From algoliasearch-client-android with MIT License 5 votes vote down vote up
@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());
}
 
Example #5
Source File: PlacesClientTest.java    From algoliasearch-client-android with MIT License 5 votes vote down vote up
@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());
}
 
Example #6
Source File: ShadowSafeAsyncTask.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
public void __constructor__() {
    realSafeAsyncTask.executor(new RoboExecutorService());
}
 
Example #7
Source File: IndexTest.java    From algoliasearch-client-android with MIT License 4 votes vote down vote up
@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");
}