1+ package com .parse ;
2+
3+ import android .database .sqlite .SQLiteException ;
4+
5+ import org .junit .After ;
6+ import org .junit .Before ;
7+ import org .junit .Rule ;
8+ import org .junit .Test ;
9+ import org .junit .rules .ExpectedException ;
10+ import org .junit .runner .RunWith ;
11+ import org .robolectric .RobolectricTestRunner ;
12+ import org .robolectric .annotation .Config ;
13+
14+ import bolts .Task ;
15+
16+ import static org .mockito .Matchers .any ;
17+ import static org .mockito .Matchers .eq ;
18+ import static org .mockito .Mockito .mock ;
19+ import static org .mockito .Mockito .when ;
20+
21+ @ RunWith (RobolectricTestRunner .class )
22+ @ Config (constants = BuildConfig .class , sdk = TestHelper .ROBOLECTRIC_SDK_VERSION )
23+ public class EventuallyPinTest {
24+
25+ @ Rule
26+ public ExpectedException thrown = ExpectedException .none ();
27+
28+ @ Before
29+ public void setUp () throws Exception {
30+ ParseObject .registerSubclass (EventuallyPin .class );
31+ ParseObject .registerSubclass (ParsePin .class );
32+ }
33+
34+ @ After
35+ public void tearDown () throws Exception {
36+ ParseObject .unregisterSubclass (EventuallyPin .class );
37+ ParseObject .unregisterSubclass (ParsePin .class );
38+ Parse .setLocalDatastore (null );
39+ ParsePlugins .reset ();
40+ }
41+
42+ @ Test
43+ public void testFailingFindAllPinned () throws Exception {
44+ OfflineStore offlineStore = mock (OfflineStore .class );
45+ Parse .setLocalDatastore (offlineStore );
46+ when (offlineStore .findFromPinAsync (eq (EventuallyPin .PIN_NAME ),
47+ any (ParseQuery .State .class ),
48+ any (ParseUser .class )))
49+ .thenReturn (Task .forError (new SQLiteException ()));
50+
51+ ParsePlugins plugins = mock (ParsePlugins .class );
52+ ParsePlugins .set (plugins );
53+ when (plugins .restClient ()).thenReturn (ParseHttpClient .createClient (null ));
54+
55+ thrown .expect (SQLiteException .class );
56+
57+ ParseTaskUtils .wait (EventuallyPin .findAllPinned ());
58+ }
59+ }
0 commit comments