Search in sources :

Example 1 with TrayItem

use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.

the class SaveNull method testSaveNullAsString.

public void testSaveNullAsString() throws Exception {
    assertEquals("default", mPref.getString(KEY, "default"));
    mPref.put(KEY, null);
    final TrayItem pref = mPref.getPref(KEY);
    assertNotNull(pref);
    assertEquals(null, pref.value());
    assertEquals(null, mPref.getString(KEY));
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem)

Example 2 with TrayItem

use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.

the class ChangedListenerTest method testApiLevel15OnChange.

public void testApiLevel15OnChange() throws Exception {
    final CountDownLatch latch = new CountDownLatch(// first time called in checkChangeListener() second time in this test
    2);
    final ArrayList<TrayItem> changed = new ArrayList<>();
    final OnTrayPreferenceChangeListener listener = new OnTrayPreferenceChangeListener() {

        @Override
        public void onTrayPreferenceChanged(final Collection<TrayItem> items) {
            changed.addAll(items);
            latch.countDown();
        }
    };
    final ContentProviderStorage storage = checkChangeListener(true, listener);
    storage.put("some", "value");
    storage.put("foo", "bar");
    new HandlerThread("change") {

        @Override
        protected void onLooperPrepared() {
            super.onLooperPrepared();
            storage.mObserver.onChange(false);
        }
    }.start();
    latch.await(3000, TimeUnit.MILLISECONDS);
    assertEquals(2, changed.size());
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem) HandlerThread(android.os.HandlerThread) ArrayList(java.util.ArrayList) Collection(java.util.Collection) OnTrayPreferenceChangeListener(net.grandcentrix.tray.core.OnTrayPreferenceChangeListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with TrayItem

use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.

the class ContentProviderStorageTest method checkReadDataWithUndefined.

private void checkReadDataWithUndefined(final ContentProviderStorage original) throws Exception {
    final ContentProviderStorage undefined = new ContentProviderStorage(getProviderMockContext(), original.getModuleName(), TrayStorage.Type.UNDEFINED);
    assertEquals(TrayStorage.Type.UNDEFINED, undefined.getType());
    assertEquals(original.getAll().size(), undefined.getAll().size());
    final TrayItem item = undefined.get(TEST_KEY);
    assertNotNull(item);
    assertEquals(original.get(TEST_KEY).value(), item.value());
    assertEquals(original.getVersion(), undefined.getVersion());
    assertEquals(original.getModuleName(), undefined.getModuleName());
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem)

Example 4 with TrayItem

use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.

the class ContentProviderStorageTest method testGetUser.

public void testGetUser() throws Exception {
    final ContentProviderStorage storage = new ContentProviderStorage(getProviderMockContext(), "testGet_User", TrayStorage.Type.USER);
    assertNull(storage.get("test"));
    assertTrue(storage.put("test", "foo"));
    final TrayItem item = storage.get("test");
    assertNotNull(item);
    assertEquals("test", item.key());
    assertEquals("foo", item.value());
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem)

Example 5 with TrayItem

use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.

the class ContentProviderStorageTest method testGetDevice.

public void testGetDevice() throws Exception {
    final ContentProviderStorage storage = new ContentProviderStorage(getProviderMockContext(), "testGet_Device", TrayStorage.Type.DEVICE);
    assertNull(storage.get("test"));
    assertTrue(storage.put("test", "foo"));
    final TrayItem item = storage.get("test");
    assertNotNull(item);
    assertEquals("test", item.key());
    assertEquals("foo", item.value());
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem)

Aggregations

TrayItem (net.grandcentrix.tray.core.TrayItem)26 Date (java.util.Date)5 Uri (android.net.Uri)3 ArrayList (java.util.ArrayList)3 NonNull (android.support.annotation.NonNull)2 TrayException (net.grandcentrix.tray.core.TrayException)2 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 MatrixCursor (android.database.MatrixCursor)1 HandlerThread (android.os.HandlerThread)1 Nullable (android.support.annotation.Nullable)1 MockContentProvider (android.test.mock.MockContentProvider)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 OnTrayPreferenceChangeListener (net.grandcentrix.tray.core.OnTrayPreferenceChangeListener)1 TrayRuntimeException (net.grandcentrix.tray.core.TrayRuntimeException)1 WrongTypeException (net.grandcentrix.tray.core.WrongTypeException)1 TestTrayModulePreferences (net.grandcentrix.tray.mock.TestTrayModulePreferences)1