Search in sources :

Example 21 with TrayItem

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

the class ContentProviderStorageTest method checkVersionAfterClear.

private void checkVersionAfterClear(final ContentProviderStorage storage) throws Exception {
    assertTrue(storage.put("key", "value"));
    final TrayItem key = storage.get("key");
    assertNotNull(key);
    assertEquals("value", key.value());
    storage.setVersion(1);
    assertEquals(1, storage.getVersion());
    storage.clear();
    assertNull(storage.get("key"));
    assertEquals(0, storage.getAll().size());
    assertEquals(1, storage.getVersion());
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem)

Example 22 with TrayItem

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

the class TrayProviderHelperTest method testUpdateEqualsCreatedAtFirst.

public void testUpdateEqualsCreatedAtFirst() throws Exception {
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
    final List<TrayItem> list = mProviderHelper.queryProvider(getUri(MODULE_A, KEY_A));
    assertNotNull(list);
    assertEquals(1, list.size());
    TrayItem itemA = list.get(0);
    assertNotNull(itemA.created());
    assertNotNull(itemA.updateTime());
    assertEquals(itemA.updateTime(), itemA.created());
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem)

Example 23 with TrayItem

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

the class TrayItemTest method testNullValues.

public void testNullValues() throws Exception {
    final TrayItem item = new TrayItem(null, null, null, null, null, null);
    assertEquals(null, item.key());
    assertEquals(null, item.value());
    assertEquals(null, item.migratedKey());
    assertEquals(null, item.module());
    assertEquals(null, item.updateTime());
    assertEquals(null, item.created());
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem)

Example 24 with TrayItem

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

the class TrayProviderHelperTest method testCursorToTrayItem.

public void testCursorToTrayItem() throws Exception {
    final MatrixCursor matrixCursor = new MatrixCursor(new String[] { TrayContract.Preferences.Columns.KEY, TrayContract.Preferences.Columns.VALUE, TrayContract.Preferences.Columns.MODULE, TrayContract.Preferences.Columns.CREATED, TrayContract.Preferences.Columns.UPDATED, TrayContract.Preferences.Columns.MIGRATED_KEY });
    final Date created = new Date();
    final Date updated = new Date();
    matrixCursor.addRow(new Object[] { "key", "value", "module", created.getTime(), updated.getTime(), "migratedKey" });
    assertTrue(matrixCursor.moveToFirst());
    final TrayItem item = TrayProviderHelper.cursorToTrayItem(matrixCursor);
    assertEquals("key", item.key());
    assertEquals("value", item.value());
    assertEquals("migratedKey", item.migratedKey());
    assertEquals("module", item.module());
    assertEquals(updated, item.updateTime());
    assertEquals(created, item.created());
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem) MatrixCursor(android.database.MatrixCursor) Date(java.util.Date)

Example 25 with TrayItem

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

the class TrayProviderHelperTest method testReadParsedProperties.

public void testReadParsedProperties() throws Exception {
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
    final List<TrayItem> list = mProviderHelper.queryProvider(getUri(MODULE_A, KEY_A));
    assertNotNull(list);
    assertEquals(1, list.size());
    TrayItem itemA = list.get(0);
    assertEquals(STRING_A, itemA.value());
    assertEquals(KEY_A, itemA.key());
    assertEquals(MODULE_A, itemA.module());
}
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