use of net.grandcentrix.tray.core.TrayItem 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());
}
use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class TrayProviderHelperTest method testUpdateChanges.
public void testUpdateChanges() 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());
Thread.sleep(10);
assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_B));
final List<TrayItem> list2 = mProviderHelper.queryProvider(getUri(MODULE_A, KEY_A));
assertNotNull(list2);
assertEquals(1, list2.size());
TrayItem itemB = list2.get(0);
//Log.v("", "diff: " + (itemA.updateTime().getTime() - itemB.updateTime().getTime()));
assertNotSame(itemA.updateTime().getTime(), itemB.updateTime().getTime());
}
use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class ReadDifferentFormat method testReadNullStringAsWrongType.
public void testReadNullStringAsWrongType() 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));
assertEquals(false, mPref.getBoolean(KEY));
try {
assertEquals(0.0f, mPref.getFloat(KEY));
fail();
} catch (WrongTypeException e) {
assertTrue(e.getMessage().contains("Float"));
assertTrue(e.getMessage().contains("null"));
}
try {
assertEquals(0l, mPref.getLong(KEY));
fail();
} catch (WrongTypeException e) {
assertTrue(e.getMessage().contains("Long"));
assertTrue(e.getMessage().contains("null"));
}
try {
assertEquals(0, mPref.getInt(KEY));
fail();
} catch (WrongTypeException e) {
assertTrue(e.getMessage().contains("Integer"));
assertTrue(e.getMessage().contains("null"));
}
}
use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class TrayItemTest method testToString.
public void testToString() throws Exception {
SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy", Locale.US);
final Date created = new Date();
final Date updated = new Date();
final TrayItem item = new TrayItem("module", "key", "migratedKey", "value", created, updated);
final String string = item.toString();
assertTrue(string.contains(item.key()));
assertTrue(string.contains(item.value()));
assertTrue(string.contains(item.migratedKey()));
assertTrue(string.contains(item.module()));
assertTrue(string.contains(sf.format(item.updateTime())));
assertTrue(string.contains(sf.format(item.created())));
}
use of net.grandcentrix.tray.core.TrayItem in project tray by grandcentrix.
the class TrayItemTest method testValues.
public void testValues() throws Exception {
final Date created = new Date();
final Date updated = new Date();
final TrayItem item = new TrayItem("module", "key", "migratedKey", "value", created, updated);
assertEquals("key", item.key());
assertEquals("value", item.value());
assertEquals("migratedKey", item.migratedKey());
assertEquals("module", item.module());
assertEquals(updated, item.updateTime());
assertEquals(created, item.created());
}
Aggregations