summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Muskalla2012-09-18 16:36:11 (EDT)
committerBenjamin Muskalla2012-09-18 16:36:11 (EDT)
commit60c1f836e5271b7a2eaa8b64f2bc4b3c2dd824e3 (patch)
tree957b169685d2d0f2f0472ef59ffc500c7c6e01cd
parent6c4e1eba3c3048829d1f2a4d70dcecdc95edb91d (diff)
downloadorg.eclipse.mylyn.tasks-60c1f836e5271b7a2eaa8b64f2bc4b3c2dd824e3.zip
org.eclipse.mylyn.tasks-60c1f836e5271b7a2eaa8b64f2bc4b3c2dd824e3.tar.gz
org.eclipse.mylyn.tasks-60c1f836e5271b7a2eaa8b64f2bc4b3c2dd824e3.tar.bz2
389842: TaskAttribute#setValues should not accept nullrefs/changes/09/7809/1
Change-Id: Ife8bbb8fa56aafd69f397582fdd3b6d4a8ac358b Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=389842
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java2
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java5
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeTest.java85
3 files changed, 91 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 5a01c9d..a923d65 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
@@ -573,6 +573,8 @@ public final class TaskAttribute {
}
public void setValues(List<String> values) {
+ Assert.isNotNull(values);
+ Assert.isTrue(!values.contains(null));
this.values.clear();
this.values.addAll(values);
}
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 04c48f1..ea22db3 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 Tasktop Technologies and others.
+ * Copyright (c) 2004, 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
@@ -24,6 +24,7 @@ import org.eclipse.mylyn.tasks.tests.core.TaskListUnmatchedContainerTest;
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.TaskDataExternalizerTest;
import org.eclipse.mylyn.tasks.tests.data.Xml11InputStreamTest;
import org.eclipse.mylyn.tasks.tests.ui.AbstractRepositoryConnectorUiTest;
@@ -46,6 +47,7 @@ import org.eclipse.mylyn.tasks.tests.ui.editor.TaskUrlHyperlinkDetectorTest;
* @author Mik Kersten
* @author Shawn Minto
* @author Steffen Pingel
+ * @author Benjamin Muskalla
*/
public class AllTasksTests {
@@ -132,6 +134,7 @@ public class AllTasksTests {
suite.addTestSuite(RepositoryClientManagerTest.class);
suite.addTestSuite(AbstractRepositoryConnectorUiTest.class);
suite.addTestSuite(SynchronizeTasksJobTest.class);
+ suite.addTestSuite(TaskAttributeTest.class);
return suite;
}
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
new file mode 100644
index 0000000..b9a3a0a
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskAttributeTest.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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 junit.framework.TestCase;
+
+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 Benjamin Muskalla
+ */
+public class TaskAttributeTest extends TestCase {
+
+ private TaskAttribute attribute;
+
+ @Override
+ protected void setUp() throws Exception {
+ TaskRepository taskRepository = new TaskRepository("kind", "repository");
+ TaskAttributeMapper mapper = new TaskAttributeMapper(taskRepository);
+ TaskData data = new TaskData(mapper, "kind", "repository", "id");
+ attribute = new TaskAttribute(data.getRoot(), "test");
+ }
+
+ public void testRegularValue() throws Exception {
+ attribute.setValue("foo");
+ assertEquals("foo", attribute.getValue());
+ }
+
+ public void testRegularValues() throws Exception {
+ attribute.setValues(Collections.singletonList("foo"));
+ assertEquals("foo", attribute.getValue());
+ }
+
+ public void testNullValue() throws Exception {
+ try {
+ attribute.setValue(null);
+ fail("Should refuse null");
+ } catch (Exception e) {
+ // expected
+ }
+ }
+
+ public void testNullAsValues() throws Exception {
+ try {
+ attribute.setValues(null);
+ fail("Should refuse null");
+ } catch (Exception e) {
+ // expected
+ }
+ }
+
+ public void testNullAsList() throws Exception {
+ try {
+ attribute.setValues(Collections.<String> singletonList(null));
+ fail("Should refuse null");
+ } catch (Exception e) {
+ // expected
+ }
+ }
+
+ public void testNullInsideValuesList() throws Exception {
+ try {
+ attribute.setValues(Arrays.asList("foo", null, "bar"));
+ fail("Should refuse null");
+ } catch (Exception e) {
+ // expected
+ }
+ }
+
+}