| author | Miles Parker | 2012-10-23 16:18:32 (EDT) |
|---|---|---|
| committer | Miles Parker | 2012-10-25 14:44:41 (EDT) |
| commit | e76c4d6905cb57324c5fbb9c66b887d20a3fd20a (patch) (side-by-side diff) | |
| tree | 4d5632f7cf89dfb3200da96eb496747c013cedd3 | |
| parent | 53af45836d0ed7fdbe9e747d0de046a93fe58326 (diff) | |
| download | org.eclipse.mylyn.tasks-e76c4d6905cb57324c5fbb9c66b887d20a3fd20a.zip org.eclipse.mylyn.tasks-e76c4d6905cb57324c5fbb9c66b887d20a3fd20a.tar.gz org.eclipse.mylyn.tasks-e76c4d6905cb57324c5fbb9c66b887d20a3fd20a.tar.bz2 | |
392688: TaskAttribute support for Unsetrefs/changes/51/8351/3
Change-Id: Ia4b44d557afcda8ae30c8b165a28e4af10b4d47d
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=392688
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 a923d65..eaa93b2 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 ea22db3..d1ffa1e 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 0ad07bd..a506fd4 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 b9a3a0a..abf7105 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); |

