Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2010-02-25 23:07:15 +0000
committerrelves2010-02-25 23:07:15 +0000
commit58da2dc6852000f312db11b114e741f617ed80b7 (patch)
treeb3cb2f524633fbb4e712cce3c3adb2c84b9fb31b /org.eclipse.mylyn.tasks.tests
parentb89116ef47f6f015aa60d4d25556cd3087432144 (diff)
downloadorg.eclipse.mylyn.tasks-58da2dc6852000f312db11b114e741f617ed80b7.tar.gz
org.eclipse.mylyn.tasks-58da2dc6852000f312db11b114e741f617ed80b7.tar.xz
org.eclipse.mylyn.tasks-58da2dc6852000f312db11b114e741f617ed80b7.zip
303387: notification's should present date/datetime diffs as localized strings
https://bugs.eclipse.org/bugs/show_bug.cgi?id=303387
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java2
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskAttributeDiffTest.java90
2 files changed, 92 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 7e3d72834..3154c7a70 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
@@ -21,6 +21,7 @@ import org.eclipse.mylyn.tasks.tests.core.TaskRepositoryLocationTest;
import org.eclipse.mylyn.tasks.tests.ui.ContextPerspectiveManagerTest;
import org.eclipse.mylyn.tasks.tests.ui.RetrieveTitleFromUrlTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskAttachmentPropertyTesterTest;
+import org.eclipse.mylyn.tasks.tests.ui.TaskAttributeDiffTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskHyperlinkDetectorTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskListSynchronizationSchedulerTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskRelationHyperlinkDetectorTest;
@@ -99,6 +100,7 @@ public class AllTasksTests {
suite.addTestSuite(TaskListSynchronizationSchedulerTest.class);
suite.addTestSuite(PlanningPartTest.class);
suite.addTestSuite(RepositoryCompletionProcessorTest.class);
+ suite.addTestSuite(TaskAttributeDiffTest.class);
// XXX long running tests, put back?
//suite.addTestSuite(QueryExportImportTest.class);
//suite.addTestSuite(BackgroundSaveTest.class);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskAttributeDiffTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskAttributeDiffTest.java
new file mode 100644
index 000000000..861658a4e
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskAttributeDiffTest.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.ui;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Collections;
+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.ui.notifications.TaskDataDiff;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+
+/**
+ * @author Robert Elves
+ */
+public class TaskAttributeDiffTest extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testDateDiff() {
+ TaskData dataA = new TaskData(new MyTaskAttributeMapper(new TaskRepository("mock", "url")), "mock", "url",
+ "1123");
+ TaskAttribute attributeA = new TaskAttribute(dataA.getRoot(), "attributeA");
+ attributeA.getMetaData().setKind(TaskAttribute.KIND_DEFAULT).setType(TaskAttribute.TYPE_DATE).setLabel(
+ "someDate:");
+ attributeA.setValue("1275068800000");
+
+ TaskData dataB = new TaskData(new MyTaskAttributeMapper(new TaskRepository("mock", "url")), "mock", "url",
+ "1123");
+ TaskAttribute attributeB = new TaskAttribute(dataB.getRoot(), "attributeA");
+ attributeB.getMetaData()
+ .setKind(TaskAttribute.KIND_DEFAULT)
+ .setType(TaskAttribute.TYPE_DATE)
+ .setLabel("mydate");
+ attributeB.setValue("1265068800000");
+
+ TaskDataDiff diff = new TaskDataDiff(new RepositoryModel(new TaskList(), new TaskRepositoryManager()), dataA,
+ dataB);
+ assertEquals(" someDate: 2010/02/01 -> 2010/05/28", diff.toString());
+
+ }
+
+ static class MyTaskAttributeMapper extends TaskAttributeMapper {
+
+ public MyTaskAttributeMapper(TaskRepository taskRepository) {
+ super(taskRepository);
+ }
+
+ @Override
+ public String getValueLabel(TaskAttribute taskAttribute) {
+ if (taskAttribute.getMetaData().getType() == TaskAttribute.TYPE_DATE) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(Long.parseLong(taskAttribute.getValue()));
+ return new SimpleDateFormat("yyyy/MM/dd").format(cal.getTime());
+ }
+ return super.getValueLabel(taskAttribute);
+ }
+
+ @Override
+ public List<String> getValueLabels(TaskAttribute taskAttribute) {
+ if (taskAttribute.getMetaData().getType() == TaskAttribute.TYPE_DATE) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(Long.parseLong(taskAttribute.getValue()));
+ return Collections.singletonList(new SimpleDateFormat("yyyy/MM/dd").format(cal.getTime()));
+ }
+ return super.getValueLabels(taskAttribute);
+ }
+
+ }
+}

Back to the top