Search in sources :

Example 1 with ActivityDescriptionDao

use of nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescriptionDao in project Gadgetbridge by Freeyourgadget.

the class EntitiesTest method testActivityDescription.

@Test
public void testActivityDescription() {
    User user = DBHelper.getUser(daoSession);
    assertNotNull(user);
    ActivityDescriptionDao descDao = daoSession.getActivityDescriptionDao();
    assertEquals(0, descDao.count());
    List<ActivityDescription> list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
    assertTrue(list.isEmpty());
    ActivityDescription desc = DBHelper.createActivityDescription(user, 10, 100, daoSession);
    assertNotNull(desc);
    assertEquals(user, desc.getUser());
    assertEquals(10, desc.getTimestampFrom());
    assertEquals(100, desc.getTimestampTo());
    List<Tag> tagList = desc.getTagList();
    assertEquals(0, tagList.size());
    Tag t1 = DBHelper.getTag(user, "Table Tennis", daoSession);
    assertNotNull(t1);
    assertEquals("Table Tennis", t1.getName());
    t1.setDescription("Table tennis training for Olympia");
    tagList.add(t1);
    list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
    assertEquals(1, list.size());
    ActivityDescription desc1 = list.get(0);
    assertEquals(desc, desc1);
    assertEquals(1, desc1.getTagList().size());
    // check for partial range overlaps
    list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
    assertEquals(1, list.size());
    // Now with a second, adjacent ActivityDescription
    ActivityDescription desc2 = DBHelper.createActivityDescription(user, 101, 200, daoSession);
    list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
    assertEquals(2, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
    assertEquals(2, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
    assertEquals(1, list.size());
    // Now with a third, partially overlapping ActivityDescription
    ActivityDescription desc3 = DBHelper.createActivityDescription(user, 5, 15, daoSession);
    list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
    assertEquals(2, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
    assertEquals(3, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
    assertEquals(2, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
    assertEquals(2, list.size());
}
Also used : ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) User(nodomain.freeyourgadget.gadgetbridge.entities.User) ActivityDescription(nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription) ActivityDescriptionDao(nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescriptionDao) Tag(nodomain.freeyourgadget.gadgetbridge.entities.Tag) Test(org.junit.Test)

Aggregations

ActivityDescription (nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription)1 ActivityDescriptionDao (nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescriptionDao)1 Tag (nodomain.freeyourgadget.gadgetbridge.entities.Tag)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 ActivityUser (nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)1 Test (org.junit.Test)1