use of net.grandcentrix.tray.mock.TestTrayModulePreferences in project tray by grandcentrix.
the class TrayTest method testEmptyKey.
public void testEmptyKey() throws Exception {
final TestTrayModulePreferences module = new TestTrayModulePreferences(getProviderMockContext(), "module");
try {
module.put("", "test");
Assert.fail();
} catch (IllegalArgumentException e) {
assertEquals("Preference key value cannot be empty.", e.getMessage());
}
}
use of net.grandcentrix.tray.mock.TestTrayModulePreferences in project tray by grandcentrix.
the class TrayTest method testGetAll.
public void testGetAll() throws Exception {
final TestTrayModulePreferences module2 = new TestTrayModulePreferences(getProviderMockContext(), "module2");
mTrayModulePref.put("test", "test");
module2.put("test", "test");
mTrayModulePref.put("test2", "test");
module2.put("test2", "test");
assertUserDatabaseSize(4);
final Collection<TrayItem> all = mTray.getAll();
assertEquals(4, all.size());
}
use of net.grandcentrix.tray.mock.TestTrayModulePreferences in project tray by grandcentrix.
the class TrayTest method testClearAllFails.
public void testClearAllFails() throws Exception {
final 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(MockProvider.AUTHORITY, mockContentProvider);
getProviderMockContext().enableMockResolver(true);
final Tray tray = new Tray(getProviderMockContext());
final TestTrayModulePreferences module2 = new TestTrayModulePreferences(getProviderMockContext(), "module2");
module2.put("blubb", "hello");
mTrayModulePref.put("test", "test");
assertUserDatabaseSize(2);
assertFalse(tray.clear());
assertUserDatabaseSize(2);
}
use of net.grandcentrix.tray.mock.TestTrayModulePreferences in project tray by grandcentrix.
the class TrayTest method testClearModules.
public void testClearModules() throws Exception {
final TestTrayModulePreferences module1 = new TestTrayModulePreferences(getProviderMockContext(), "module1");
final TestTrayModulePreferences module2 = new TestTrayModulePreferences(getProviderMockContext(), "module2");
module1.put("test", "test");
module2.put("test", "test");
module1.put("test2", "test");
module2.put("test2", "test");
assertUserDatabaseSize(4);
Tray.clear(new TestTrayModulePreferences(getProviderMockContext(), "module1"));
assertUserDatabaseSize(2);
Tray.clear(new TestTrayModulePreferences(getProviderMockContext(), "module2"));
assertUserDatabaseSize(0);
module1.put("test", "test");
module2.put("test", "test");
Tray.clear((TrayPreferences) null);
assertUserDatabaseSize(2);
}
use of net.grandcentrix.tray.mock.TestTrayModulePreferences in project tray by grandcentrix.
the class RenamePreference method rename.
private void rename(final TrayStorage.Type type) throws Exception {
//create old Preference
final TestTrayModulePreferences oldOne = new TestTrayModulePreferences(getProviderMockContext(), "oldOne", type);
oldOne.put("key", "value");
assertEquals(1, oldOne.getAll().size());
assertEquals(1, oldOne.getInternalStorage().getVersion());
final TestTrayModulePreferences newOne = new TestTrayModulePreferences(getProviderMockContext(), "newOne") {
@Override
protected void onCreate(final int newVersion) {
super.onCreate(newVersion);
annexModule("oldOne");
}
};
assertEquals(1, newOne.getAll().size());
assertEquals(0, oldOne.getAll().size());
// TestTrayModulePreferences default version is 1. 0 means all metadata is deleted
assertEquals(0, oldOne.getInternalStorage().getVersion());
}
Aggregations