Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2015-11-17 17:22:52 -0500
committerGerrit Code Review @ Eclipse.org2015-11-19 18:31:11 -0500
commitcc0295a24e13d01c25b764ca6a7c0302f97781aa (patch)
tree276612df7b45ab49af82ab2c1e7a787ab2326831
parentcaeb07755d6648012df20b98664dc11a3101d7e5 (diff)
downloadorg.eclipse.mylyn.tasks-cc0295a24e13d01c25b764ca6a7c0302f97781aa.tar.gz
org.eclipse.mylyn.tasks-cc0295a24e13d01c25b764ca6a7c0302f97781aa.tar.xz
org.eclipse.mylyn.tasks-cc0295a24e13d01c25b764ca6a7c0302f97781aa.zip
482429: getValueLabels should fall back to attribute.getOption when
getOptions does not contain a value Change-Id: I3b45ff4be32d9534ea0cf686892b058332024aec Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=482429
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java2
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeMapperTest.java68
2 files changed, 70 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java
index 05e9d3594..257fe0f92 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java
@@ -258,6 +258,8 @@ public class TaskAttributeMapper {
String option = options.get(value);
if (option != null) {
value = option;
+ } else if (taskAttribute.getOption(value) != null) {
+ value = taskAttribute.getOption(value);
}
result.add(value);
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeMapperTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeMapperTest.java
index 76b6a9304..6c465454a 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeMapperTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeMapperTest.java
@@ -11,6 +11,8 @@
package org.eclipse.mylyn.tasks.tests.data;
+import java.util.Map;
+
import junit.framework.TestCase;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -19,6 +21,9 @@ import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
import org.eclipse.mylyn.tasks.core.data.TaskData;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
/**
* @author Steffen Pingel
*/
@@ -96,4 +101,67 @@ public class TaskAttributeMapperTest extends TestCase {
mapper.equals(attributeNew, attributeOld));
}
+ public void testGetValueLabels() throws Exception {
+ TaskAttributeMapper mapper = mapperWith2Options();
+ TaskAttribute attribute = data.getRoot().createAttribute("id");
+
+ assertEquals(ImmutableList.of(), mapper.getValueLabels(attribute));
+
+ attribute.setValue("1");
+ assertEquals(ImmutableList.of("a"), mapper.getValueLabels(attribute));
+
+ attribute.setValue("2");
+ assertEquals(ImmutableList.of("b"), mapper.getValueLabels(attribute));
+
+ attribute = data.getRoot().createAttribute("id");
+ attribute.addValue("1");
+ attribute.addValue("2");
+ assertEquals(ImmutableList.of("a", "b"), mapper.getValueLabels(attribute));
+
+ attribute = data.getRoot().createAttribute("id");
+ attribute.addValue("2");
+ attribute.addValue("1");
+ assertEquals(ImmutableList.of("b", "a"), mapper.getValueLabels(attribute));
+ }
+
+ public void testGetValueLabelsUnmappedOption() throws Exception {
+ TaskAttributeMapper mapper = mapperWith2Options();
+ TaskAttribute attribute = attributeWithUnmappedOption();
+
+ assertEquals(ImmutableList.of(), mapper.getValueLabels(attribute));
+
+ attribute.setValue("1");
+ assertEquals(ImmutableList.of("a"), mapper.getValueLabels(attribute));
+
+ attribute.setValue("unMappedOption");
+ assertEquals(ImmutableList.of("unMappedOptionLabel"), mapper.getValueLabels(attribute));
+
+ attribute = attributeWithUnmappedOption();
+ attribute.addValue("unMappedOption");
+ attribute.addValue("2");
+ assertEquals(ImmutableList.of("unMappedOptionLabel", "b"), mapper.getValueLabels(attribute));
+
+ attribute = attributeWithUnmappedOption();
+ attribute.addValue("2");
+ attribute.addValue("unMappedOption");
+ assertEquals(ImmutableList.of("b", "unMappedOptionLabel"), mapper.getValueLabels(attribute));
+ }
+
+ private TaskAttributeMapper mapperWith2Options() {
+ TaskAttributeMapper mapper = new TaskAttributeMapper(taskRepository) {
+ @Override
+ public Map<String, String> getOptions(TaskAttribute attribute) {
+ return ImmutableMap.of("1", "a", "2", "b");
+ }
+ };
+ return mapper;
+ }
+
+ private TaskAttribute attributeWithUnmappedOption() {
+ TaskAttribute attribute;
+ attribute = data.getRoot().createAttribute("id");
+ attribute.putOption("unMappedOption", "unMappedOptionLabel");
+ return attribute;
+ }
+
}

Back to the top