diff --git a/Parse/src/main/java/com/parse/EventuallyPin.java b/Parse/src/main/java/com/parse/EventuallyPin.java index 7e0ee444e..a50b632f8 100644 --- a/Parse/src/main/java/com/parse/EventuallyPin.java +++ b/Parse/src/main/java/com/parse/EventuallyPin.java @@ -166,7 +166,7 @@ public static Task> findAllPinned(Collection exclude // We need pass in a null user because we don't want the query to fetch the current user // from LDS. - return query.findInBackground().continueWithTask(new Continuation, Task>>() { + return query.findInBackground().onSuccessTask(new Continuation, Task>>() { @Override public Task> then(Task> task) throws Exception { final List pins = task.getResult(); diff --git a/Parse/src/test/java/com/parse/EventuallyPinTest.java b/Parse/src/test/java/com/parse/EventuallyPinTest.java new file mode 100644 index 000000000..e3942c35d --- /dev/null +++ b/Parse/src/test/java/com/parse/EventuallyPinTest.java @@ -0,0 +1,59 @@ +package com.parse; + +import android.database.sqlite.SQLiteException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import bolts.Task; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = TestHelper.ROBOLECTRIC_SDK_VERSION) +public class EventuallyPinTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + ParseObject.registerSubclass(EventuallyPin.class); + ParseObject.registerSubclass(ParsePin.class); + } + + @After + public void tearDown() throws Exception { + ParseObject.unregisterSubclass(EventuallyPin.class); + ParseObject.unregisterSubclass(ParsePin.class); + Parse.setLocalDatastore(null); + ParsePlugins.reset(); + } + + @Test + public void testFailingFindAllPinned() throws Exception { + OfflineStore offlineStore = mock(OfflineStore.class); + Parse.setLocalDatastore(offlineStore); + when(offlineStore.findFromPinAsync(eq(EventuallyPin.PIN_NAME), + any(ParseQuery.State.class), + any(ParseUser.class))) + .thenReturn(Task.forError(new SQLiteException())); + + ParsePlugins plugins = mock(ParsePlugins.class); + ParsePlugins.set(plugins); + when(plugins.restClient()).thenReturn(ParseHttpClient.createClient(null)); + + thrown.expect(SQLiteException.class); + + ParseTaskUtils.wait(EventuallyPin.findAllPinned()); + } +} \ No newline at end of file