use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class LocalDbUnitTests method getAllPathsTest.
@Test
public void getAllPathsTest() throws Exception {
ArrayList<Path> paths = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < random.nextInt(10) + 1; ++i) {
paths.add(new Path(random.nextInt(100), TestUtils.randomString(), TestUtils.randomString(), random.nextBoolean()));
}
for (Path path : paths) {
ContentValues values = new PathDao.Builder().id(path.getId()).name(path.getName()).info(path.getInfo()).active(path.getActive()).build();
localDbHandler.getDb().insert(PathDao.TABLE, CONFLICT_FAIL, values);
}
TestObserver<List<Path>> testObserver = PathDao.getAllPaths(localDbHandler.getDb()).test();
testObserver.assertSubscribed();
testObserver.awaitCount(1);
testObserver.assertNoErrors();
testObserver.assertValue(dbPaths -> {
Assert.assertEquals(paths.size(), dbPaths.size());
for (int i = 0; i < paths.size(); ++i) {
Assert.assertEquals(paths.get(i), dbPaths.get(i));
}
return true;
});
testObserver.onComplete();
}
use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class LocalDbUnitTests method insertPathListTest.
@Test
public void insertPathListTest() throws Exception {
ArrayList<Path> paths = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < random.nextInt(10) + 1; ++i) {
paths.add(new Path(random.nextInt(100), TestUtils.randomString(), TestUtils.randomString(), random.nextBoolean()));
}
PathDao.insertPathList(localDbHandler.getDb(), paths);
Cursor cursor = localDbHandler.getDb().query("SELECT * FROM " + PathDao.TABLE);
Assert.assertEquals(paths.size(), cursor.getCount());
for (Path path : paths) {
Assert.assertTrue(cursor.moveToNext());
Assert.assertEquals(path.getId().intValue(), cursor.getInt(cursor.getColumnIndex(PathDao.ID)));
Assert.assertEquals(path.getName(), cursor.getString(cursor.getColumnIndex(PathDao.NAME)));
Assert.assertEquals(path.getInfo(), cursor.getString(cursor.getColumnIndex(PathDao.INFO)));
Assert.assertEquals(path.getActive(), cursor.getInt(cursor.getColumnIndex(PathDao.ACTIVE)) == 1);
}
Assert.assertFalse(cursor.moveToNext());
}
use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class TimetableFragmentTest method titleBarTest.
/**
* Test if correct title bar set
*/
@Test
public void titleBarTest() throws Exception {
String expectedTitle = TestUtils.randomString();
Path path = data.getPaths().get(1);
path.setInfo(expectedTitle);
data.getPaths().add(1, path);
appData.setValue(RxResponse.success(data));
startFragment(timetableFragment);
timetableFragment.getBinding().executePendingBindings();
View view = timetableFragment.getView();
Assert.assertNotNull(view);
Toolbar toolbar = view.findViewById(R.id.timetable_title_bar);
Assert.assertEquals(expectedTitle, toolbar.getTitle().toString());
}
use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class LocalDbUnitTests method getAllPathsTest.
@Test
public void getAllPathsTest() throws Exception {
ArrayList<Path> paths = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < random.nextInt(10) + 1; ++i) {
paths.add(new Path(random.nextInt(100), TestUtils.randomString(), TestUtils.randomString(), random.nextBoolean()));
}
for (Path path : paths) {
ContentValues values = new PathDao.Builder().id(path.getId()).name(path.getName()).info(path.getInfo()).active(path.getActive()).build();
localDbHandler.getDb().insert(PathDao.TABLE, CONFLICT_FAIL, values);
}
TestObserver<List<Path>> testObserver = PathDao.getAllPaths(localDbHandler.getDb()).test();
testObserver.assertSubscribed();
testObserver.awaitCount(1);
testObserver.assertNoErrors();
testObserver.assertValue(dbPaths -> {
Assert.assertEquals(paths.size(), dbPaths.size());
for (int i = 0; i < paths.size(); ++i) {
Assert.assertEquals(paths.get(i), dbPaths.get(i));
}
return true;
});
testObserver.onComplete();
}
use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class LocalDbUnitTests method insertPathListTest.
@Test
public void insertPathListTest() throws Exception {
ArrayList<Path> paths = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < random.nextInt(10) + 1; ++i) {
paths.add(new Path(random.nextInt(100), TestUtils.randomString(), TestUtils.randomString(), random.nextBoolean()));
}
PathDao.insertPathList(localDbHandler.getDb(), paths);
Cursor cursor = localDbHandler.getDb().query("SELECT * FROM " + PathDao.TABLE);
Assert.assertEquals(paths.size(), cursor.getCount());
for (Path path : paths) {
Assert.assertTrue(cursor.moveToNext());
Assert.assertEquals(path.getId().intValue(), cursor.getInt(cursor.getColumnIndex(PathDao.ID)));
Assert.assertEquals(path.getName(), cursor.getString(cursor.getColumnIndex(PathDao.NAME)));
Assert.assertEquals(path.getInfo(), cursor.getString(cursor.getColumnIndex(PathDao.INFO)));
Assert.assertEquals(path.getActive(), cursor.getInt(cursor.getColumnIndex(PathDao.ACTIVE)) == 1);
}
Assert.assertFalse(cursor.moveToNext());
}
Aggregations