Search in sources :

Example 1 with Path

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();
}
Also used : Path(com.jakdor.labday.common.model.Path) ContentValues(android.content.ContentValues) Random(java.util.Random) PathDao(com.jakdor.labday.common.dao.PathDao) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with Path

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());
}
Also used : Path(com.jakdor.labday.common.model.Path) Random(java.util.Random) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 3 with Path

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());
}
Also used : Path(com.jakdor.labday.common.model.Path) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) Test(org.junit.Test)

Example 4 with Path

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();
}
Also used : Path(com.jakdor.labday.common.model.Path) ContentValues(android.content.ContentValues) Random(java.util.Random) PathDao(com.jakdor.labday.common.dao.PathDao) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 5 with Path

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());
}
Also used : Path(com.jakdor.labday.common.model.Path) Random(java.util.Random) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Test(org.junit.Test)

Aggregations

Path (com.jakdor.labday.common.model.Path)10 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Random (java.util.Random)4 ContentValues (android.content.ContentValues)3 Cursor (android.database.Cursor)3 PathDao (com.jakdor.labday.common.dao.PathDao)2 List (java.util.List)2 NestedScrollView (android.support.v4.widget.NestedScrollView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 TextView (android.widget.TextView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AppData (com.jakdor.labday.common.model.AppData)1 TimetableAdapter (com.jakdor.labday.view.adapter.TimetableAdapter)1