diff options
author | Steffen Pingel | 2012-10-15 16:35:03 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2013-10-06 04:01:00 +0000 |
commit | 0c54cd5defb84ae6618e3983e0b5264213009c7c (patch) | |
tree | 3cd8bc110d9bbbc4de40316294fd597f58f3d022 /org.eclipse.mylyn.tasks.tests/src/org/eclipse | |
parent | c42142e719054260af4d46e05f05c47536539bce (diff) | |
download | org.eclipse.mylyn.tasks-0c54cd5defb84ae6618e3983e0b5264213009c7c.tar.gz org.eclipse.mylyn.tasks-0c54cd5defb84ae6618e3983e0b5264213009c7c.tar.xz org.eclipse.mylyn.tasks-0c54cd5defb84ae6618e3983e0b5264213009c7c.zip |
391953: add tests for TaskDataDiff
Change-Id: I51b9c2f85675e2e6ca92ffda39228826114bdb5b
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=391953
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests/src/org/eclipse')
-rw-r--r-- | org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java | 2 | ||||
-rw-r--r-- | org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java | 124 |
2 files changed, 126 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java index 2db09cc2b..d490fa4dc 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java @@ -28,6 +28,7 @@ import org.eclipse.mylyn.tasks.tests.core.TaskRepositoryLocationTest; import org.eclipse.mylyn.tasks.tests.core.TaskRepositoryTest; import org.eclipse.mylyn.tasks.tests.data.TaskAttributeMapperTest; import org.eclipse.mylyn.tasks.tests.data.TaskAttributeTest; +import org.eclipse.mylyn.tasks.tests.data.TaskDataDiffTest; import org.eclipse.mylyn.tasks.tests.data.TaskDataExternalizerTest; import org.eclipse.mylyn.tasks.tests.data.Xml11InputStreamTest; import org.eclipse.mylyn.tasks.tests.ui.AbstractRepositoryConnectorUiTest; @@ -144,6 +145,7 @@ public class AllTasksTests { suite.addTestSuite(ScheduledTaskContainerTest.class); suite.addTestSuite(RepositoryConnectorContributorTest.class); suite.addTestSuite(TaskInitializationDataTest.class); + suite.addTestSuite(TaskDataDiffTest.class); return suite; } diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java new file mode 100644 index 000000000..de6db56d2 --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.tasks.tests.data; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.mylyn.internal.tasks.core.RepositoryModel; +import org.eclipse.mylyn.internal.tasks.core.TaskList; +import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager; +import org.eclipse.mylyn.internal.tasks.core.TaskTask; +import org.eclipse.mylyn.internal.tasks.core.data.TaskAttributeDiff; +import org.eclipse.mylyn.internal.tasks.core.data.TaskDataDiff; +import org.eclipse.mylyn.tasks.core.IRepositoryManager; +import org.eclipse.mylyn.tasks.core.ITask; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.core.data.ITaskAttributeDiff; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; +import org.eclipse.mylyn.tasks.core.data.TaskData; +import org.junit.Test; + +/** + * @author Steffen Pingel + */ +public class TaskDataDiffTest extends TestCase { + + private RepositoryModel model; + + private TaskRepository repository; + + private TaskAttributeMapper mapper; + + private TaskData newData; + + private TaskData oldData; + + @Override + protected void setUp() throws Exception { + ITask task = new TaskTask("kind", "url", "1"); + repository = new TaskRepository(task.getConnectorKind(), task.getRepositoryUrl()); + mapper = new TaskAttributeMapper(repository); + IRepositoryManager repositoryManager = new TaskRepositoryManager(); + repositoryManager.addRepository(repository); + TaskList taskList = new TaskList(); + taskList.addTask(task); + model = new RepositoryModel(taskList, repositoryManager); + + newData = new TaskData(mapper, repository.getConnectorKind(), repository.getUrl(), "1"); + oldData = new TaskData(mapper, repository.getConnectorKind(), repository.getUrl(), "1"); + } + + @Test + public void testGetChangedAttributes() { + TaskDataDiff diff = new TaskDataDiff(model, newData, oldData); + assertEquals(Collections.emptySet(), diff.getChangedAttributes()); + } + + @Test + public void testGetChangedAttributesMultiple() { + TaskAttribute attributeCustom = newData.getRoot().createAttribute("custom"); + attributeCustom.setValue("1"); + TaskAttribute attributeSummary = newData.getRoot().createAttribute(TaskAttribute.SUMMARY); + attributeSummary.setValue("1"); + TaskDataDiff diff = new TaskDataDiff(model, newData, oldData); + assertEquals(Collections.singleton(new TaskAttributeDiff(null, attributeSummary)), diff.getChangedAttributes()); + } + + @Test + public void testGetChangedAttributesMultipleKind() { + TaskAttribute attributeCustom = newData.getRoot().createAttribute("custom"); + attributeCustom.setValue("1"); + attributeCustom.getMetaData().setKind("kind"); + TaskAttribute attributeSummary = newData.getRoot().createAttribute(TaskAttribute.SUMMARY); + attributeSummary.setValue("1"); + TaskDataDiff diff = new TaskDataDiff(model, newData, oldData); + List<TaskAttributeDiff> expected = Arrays.asList(new TaskAttributeDiff(null, attributeSummary), + new TaskAttributeDiff(null, attributeCustom)); + assertEquals(new LinkedHashSet<ITaskAttributeDiff>(expected), diff.getChangedAttributes()); + } + + @Test + public void testGetChangedAttributesSummary() { + TaskAttribute attribute = newData.getRoot().createAttribute(TaskAttribute.SUMMARY); + attribute.setValue("text"); + TaskDataDiff diff = new TaskDataDiff(model, newData, oldData); + assertEquals(Collections.singleton(new TaskAttributeDiff(null, attribute)), diff.getChangedAttributes()); + } + + @Test + public void testGetChangedAttributesSummaryEmptyValue() { + newData.getRoot().createAttribute(TaskAttribute.SUMMARY); + TaskDataDiff diff = new TaskDataDiff(model, newData, oldData); + assertEquals(Collections.emptySet(), diff.getChangedAttributes()); + } + + @Test + public void testHasChanges() { + TaskDataDiff diff = new TaskDataDiff(model, newData, oldData); + assertTrue(diff.hasChanged()); + } + + @Test + public void testHasChangesAttribute() { + newData.getRoot().createAttribute(TaskAttribute.SUMMARY).setValue("text"); + TaskDataDiff diff = new TaskDataDiff(model, newData, oldData); + assertTrue(diff.hasChanged()); + diff.setHasChanged(false); + assertFalse(diff.hasChanged()); + } +} |