Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit e0bdd76

Browse files
author
Clément Le Provost
committed
Fix unit tests: Robolectric-compliant executor service
Robolectric cannot handle custom executors in `AsyncTask`, so we substitute the client’s executor with a Robolectric-compliant one.
1 parent 9ab6ea6 commit e0bdd76

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

algoliasearch/src/test/java/com/algolia/search/saas/BrowseIteratorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.json.JSONArray;
3131
import org.json.JSONObject;
3232
import org.junit.Test;
33+
import org.mockito.internal.util.reflection.Whitebox;
34+
import org.robolectric.util.concurrent.RoboExecutorService;
3335

3436
import java.util.ArrayList;
3537
import java.util.List;
@@ -51,6 +53,9 @@ public class BrowseIteratorTest extends PowerMockTestCase {
5153
public void setUp() throws Exception {
5254
super.setUp();
5355
client = new Client(Helpers.app_id, Helpers.api_key);
56+
// WARNING: Robolectric cannot work with custom executors in `AsyncTask`, so we substitute the client's
57+
// executor with a Robolectric-compliant one.
58+
Whitebox.setInternalState(client, "searchExecutorService", new RoboExecutorService());
5459
indexName = Helpers.safeIndexName("àlgol?à-android");
5560
index = client.initIndex(indexName);
5661

algoliasearch/src/test/java/com/algolia/search/saas/IndexTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.json.JSONObject;
2828
import org.junit.Test;
2929
import org.mockito.internal.util.reflection.Whitebox;
30+
import org.robolectric.util.concurrent.RoboExecutorService;
3031

3132
import java.util.ArrayList;
3233
import java.util.Arrays;
@@ -65,6 +66,10 @@ public class IndexTest extends PowerMockTestCase {
6566
public void setUp() throws Exception {
6667
super.setUp();
6768
client = new Client(Helpers.app_id, Helpers.api_key);
69+
// WARNING: Robolectric cannot work with custom executors in `AsyncTask`, so we substitute the client's
70+
// executor with a Robolectric-compliant one.
71+
Whitebox.setInternalState(client, "searchExecutorService", new RoboExecutorService());
72+
6873
indexName = Helpers.safeIndexName("àlgol?à-android");
6974
index = client.initIndex(indexName);
7075

0 commit comments

Comments
 (0)