Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java17
-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/TaskDataStoreTest.java31
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeTest.java21
4 files changed, 70 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java
index a923d6573..eaa93b289 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java
@@ -24,6 +24,7 @@ import org.eclipse.core.runtime.Assert;
*
* @author Rob Elves
* @author Steffen Pingel
+ * @author Miles Parker
* @since 3.0
*/
public final class TaskAttribute {
@@ -500,7 +501,9 @@ public final class TaskAttribute {
}
/**
- * @return empty String if not available
+ * Returns the current value for a single value attribute. For a multi-value attribute, returns the first value.
+ * Note: returns an empty string if the value has not been set <em>or</em> if the value is actually an empty string.
+ * To determine whether a value has been explicitly set, use {@link #hasValue()}.
*/
public String getValue() {
if (values.size() > 0) {
@@ -514,6 +517,18 @@ public final class TaskAttribute {
return Collections.unmodifiableList(values);
}
+ /**
+ * Indicates whether any value(s) are currently set for this attribute. Note that this is a different case from
+ * testing whether or not {@link #getValue()} returns an empty string, as it is possible that an empty string value
+ * has been explicitly set for the attribute. Call {@link #clearValues()} to return the attribute to the unset
+ * state.
+ *
+ * @return true if any value is set (may be an empty string), false if no value is set.
+ */
+ public boolean hasValue() {
+ return values.size() > 0;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
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 ea22db338..d1ffa1e9e 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
@@ -48,6 +48,7 @@ import org.eclipse.mylyn.tasks.tests.ui.editor.TaskUrlHyperlinkDetectorTest;
* @author Shawn Minto
* @author Steffen Pingel
* @author Benjamin Muskalla
+ * @author Miles Parker
*/
public class AllTasksTests {
@@ -129,6 +130,7 @@ public class AllTasksTests {
suite.addTestSuite(MultipleTaskHyperlinkDetectorTest.class);
suite.addTestSuite(RegionComparatorTest.class);
suite.addTestSuite(PriorityLevelTest.class);
+ suite.addTestSuite(TaskAttributeTest.class);
suite.addTestSuite(TaskAttributeMapperTest.class);
suite.addTestSuite(SupportHandlerManagerTest.class);
suite.addTestSuite(RepositoryClientManagerTest.class);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
index 0ad07bd3b..a506fd4cc 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
@@ -257,4 +257,35 @@ public class TaskDataStoreTest extends TestCase {
}
}
+ public void testReadWriteSetValue() throws Exception {
+ setupData();
+ TaskAttribute attribute = data.getRoot().createAttribute("attribute");
+ assertFalse(attribute.hasValue());
+ attribute.setValue("foo");
+ assertTrue(attribute.hasValue());
+
+ File file = File.createTempFile("mylyn", null);
+ file.deleteOnExit();
+ storage.putTaskData(file, state);
+
+ TaskDataState state2 = storage.getTaskDataState(file);
+ assertTrue(state2.getRepositoryData().getRoot().getAttribute("attribute").hasValue());
+ }
+
+ public void testReadWriteUnsetValue() throws Exception {
+ setupData();
+ TaskAttribute attribute = data.getRoot().createAttribute("attribute");
+ assertFalse(attribute.hasValue());
+ attribute.setValue("foo");
+ assertTrue(attribute.hasValue());
+ attribute.clearValues();
+ assertFalse(attribute.hasValue());
+
+ File file = File.createTempFile("mylyn", null);
+ file.deleteOnExit();
+ storage.putTaskData(file, state);
+
+ TaskDataState state2 = storage.getTaskDataState(file);
+ assertFalse(state2.getRepositoryData().getRoot().getAttribute("attribute").hasValue());
+ }
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeTest.java
index b9a3a0a2e..abf71052f 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeTest.java
@@ -23,6 +23,7 @@ import org.eclipse.mylyn.tasks.core.data.TaskData;
/**
* @author Benjamin Muskalla
+ * @author Miles Parker
*/
public class TaskAttributeTest extends TestCase {
@@ -36,6 +37,13 @@ public class TaskAttributeTest extends TestCase {
attribute = new TaskAttribute(data.getRoot(), "test");
}
+ public void testGetValue() {
+ attribute.setValue("baz");
+ assertEquals("baz", attribute.getValue());
+ attribute.setValue("bee");
+ assertEquals("bee", attribute.getValue());
+ }
+
public void testRegularValue() throws Exception {
attribute.setValue("foo");
assertEquals("foo", attribute.getValue());
@@ -46,6 +54,19 @@ public class TaskAttributeTest extends TestCase {
assertEquals("foo", attribute.getValue());
}
+ public void testHasValue() {
+ assertFalse(attribute.hasValue());
+
+ attribute.setValue("description");
+ assertTrue(attribute.hasValue());
+
+ attribute.clearValues();
+ assertFalse(attribute.hasValue());
+
+ attribute.setValue("description");
+ assertTrue(attribute.hasValue());
+ }
+
public void testNullValue() throws Exception {
try {
attribute.setValue(null);

Back to the top