You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tasks/app/src/androidTest/java/org/tasks/data/CaldavDaoTests.java

71 lines
2.2 KiB
Java

package org.tasks.data;
import static com.natpryce.makeiteasy.MakeItEasy.with;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.tasks.makers.TagDataMaker.newTagData;
import static org.tasks.makers.TagMaker.TAGDATA;
import static org.tasks.makers.TagMaker.TASK;
import static org.tasks.makers.TagMaker.newTag;
import static org.tasks.makers.TaskMaker.ID;
import static org.tasks.makers.TaskMaker.newTask;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
@RunWith(AndroidJUnit4.class)
public class CaldavDaoTests extends InjectingTestCase {
@Inject TaskDao taskDao;
@Inject TagDao tagDao;
@Inject TagDataDao tagDataDao;
@Inject CaldavDao caldavDao;
@Test
public void getCaldavTasksWithTags() {
Task task = newTask(with(ID, 1L));
taskDao.createNew(task);
TagData one = newTagData();
TagData two = newTagData();
tagDataDao.createNew(one);
tagDataDao.createNew(two);
tagDao.insert(newTag(with(TASK, task), with(TAGDATA, one)));
tagDao.insert(newTag(with(TASK, task), with(TAGDATA, two)));
caldavDao.insert(new CaldavTask(task.getId(), "calendar"));
assertEquals(singletonList(task.getId()), caldavDao.getTasksWithTags());
}
@Test
public void ignoreNonCaldavTaskWithTags() {
Task task = newTask(with(ID, 1L));
taskDao.createNew(task);
TagData tag = newTagData();
tagDataDao.createNew(tag);
tagDao.insert(newTag(with(TASK, task), with(TAGDATA, tag)));
assertTrue(caldavDao.getTasksWithTags().isEmpty());
}
@Test
public void ignoreCaldavTaskWithoutTags() {
Task task = newTask(with(ID, 1L));
taskDao.createNew(task);
tagDataDao.createNew(newTagData());
caldavDao.insert(new CaldavTask(task.getId(), "calendar"));
assertTrue(caldavDao.getTasksWithTags().isEmpty());
}
@Override
protected void inject(TestComponent component) {
component.inject(this);
}
}