Search in sources :

Example 1 with MockContentProvider

use of android.test.mock.MockContentProvider in project tray by grandcentrix.

the class TrayProviderHelperTest method testQueryFails.

public void testQueryFails() throws Exception {
    Uri uri = new TrayUri(getProviderMockContext()).get();
    MockContentProvider mockContentProvider = new MockContentProvider(getProviderMockContext()) {

        @Override
        public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) {
            throw new IllegalStateException("something serious is wrong");
        }
    };
    getProviderMockContext().addProvider(uri.getAuthority(), mockContentProvider);
    getProviderMockContext().enableMockResolver(true);
    try {
        mProviderHelper.queryProvider(getUri(MODULE_A, KEY_A));
        fail("did not throw");
    } catch (TrayException e) {
        e.getCause().getMessage().equals("something serious is wrong");
    }
    final List<TrayItem> trayItems = mProviderHelper.queryProviderSafe(getUri(MODULE_A, KEY_A));
    assertEquals(0, trayItems.size());
}
Also used : TrayException(net.grandcentrix.tray.core.TrayException) TrayItem(net.grandcentrix.tray.core.TrayItem) MockContentProvider(android.test.mock.MockContentProvider) Uri(android.net.Uri)

Example 2 with MockContentProvider

use of android.test.mock.MockContentProvider in project tray by grandcentrix.

the class TrayProviderHelperTest method testClearFails.

public void testClearFails() throws Exception {
    Uri uri = new TrayUri(getProviderMockContext()).get();
    MockContentProvider mockContentProvider = new MockContentProvider(getProviderMockContext()) {

        @Override
        public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
            throw new IllegalStateException("something serious is wrong");
        }
    };
    getProviderMockContext().addProvider(uri.getAuthority(), mockContentProvider);
    getProviderMockContext().enableMockResolver(true);
    assertFalse(mProviderHelper.clear());
}
Also used : MockContentProvider(android.test.mock.MockContentProvider) Uri(android.net.Uri)

Example 3 with MockContentProvider

use of android.test.mock.MockContentProvider in project tray by grandcentrix.

the class TrayProviderHelperTest method testClearButFails.

public void testClearButFails() throws Exception {
    Uri uri = new TrayUri(getProviderMockContext()).get();
    MockContentProvider mockContentProvider = new MockContentProvider(getProviderMockContext()) {

        @Override
        public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
            throw new IllegalStateException("something serious is wrong");
        }
    };
    getProviderMockContext().addProvider(uri.getAuthority(), mockContentProvider);
    getProviderMockContext().enableMockResolver(true);
    assertFalse(mProviderHelper.clearBut(new AppPreferences(getProviderMockContext())));
}
Also used : MockContentProvider(android.test.mock.MockContentProvider) AppPreferences(net.grandcentrix.tray.AppPreferences) Uri(android.net.Uri)

Example 4 with MockContentProvider

use of android.test.mock.MockContentProvider in project tray by grandcentrix.

the class TrayProviderHelperTest method testPersistFails.

public void testPersistFails() throws Exception {
    Uri uri = new TrayUri(getProviderMockContext()).get();
    MockContentProvider mockContentProvider = new MockContentProvider(getProviderMockContext()) {

        @Override
        public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
            throw new IllegalStateException("something serious is wrong");
        }
    };
    getProviderMockContext().addProvider(uri.getAuthority(), mockContentProvider);
    getProviderMockContext().enableMockResolver(true);
    assertFalse(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
}
Also used : MockContentProvider(android.test.mock.MockContentProvider) Uri(android.net.Uri)

Example 5 with MockContentProvider

use of android.test.mock.MockContentProvider in project tray by grandcentrix.

the class TrayProviderHelperTest method testRemoveFails.

public void testRemoveFails() throws Exception {
    Uri uri = new TrayUri(getProviderMockContext()).get();
    MockContentProvider mockContentProvider = new MockContentProvider(getProviderMockContext()) {

        @Override
        public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
            throw new IllegalStateException("something serious is wrong");
        }
    };
    getProviderMockContext().addProvider(uri.getAuthority(), mockContentProvider);
    getProviderMockContext().enableMockResolver(true);
    assertEquals(0, mProviderHelper.removeAndCount(getUri(MODULE_A, KEY_A)));
}
Also used : MockContentProvider(android.test.mock.MockContentProvider) Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)11 MockContentProvider (android.test.mock.MockContentProvider)11 ContentValues (android.content.ContentValues)1 AppPreferences (net.grandcentrix.tray.AppPreferences)1 TrayException (net.grandcentrix.tray.core.TrayException)1 TrayItem (net.grandcentrix.tray.core.TrayItem)1 TestTrayModulePreferences (net.grandcentrix.tray.mock.TestTrayModulePreferences)1