Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2014-03-14 13:55:38 +0000
committerTomasz Zarna2014-04-03 08:30:38 +0000
commitf3ef438e9a82a7c8741473484a39e4f8eee70488 (patch)
treeed57575ebef219cfc32becb14d933570063cbeba
parent9883b0277b3e7e2391ae95271580a1071c721072 (diff)
downloadorg.eclipse.mylyn.tasks-f3ef438e9a82a7c8741473484a39e4f8eee70488.tar.gz
org.eclipse.mylyn.tasks-f3ef438e9a82a7c8741473484a39e4f8eee70488.tar.xz
org.eclipse.mylyn.tasks-f3ef438e9a82a7c8741473484a39e4f8eee70488.zip
430391: Increase test coverage of PersonProposalProvider to 83%
Change-Id: I8ed77bb2a18760841a61a0a23a69f329b4c89788 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=430391
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java116
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java6
2 files changed, 87 insertions, 35 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java
index 7dba45e69..5e4a896d9 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 Frank Becker and others.
+ * Copyright (c) 2004, 2014 Frank Becker 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
@@ -28,6 +28,8 @@ import org.eclipse.mylyn.internal.tasks.ui.PersonContentProposal;
import org.eclipse.mylyn.internal.tasks.ui.PersonProposalProvider;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
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;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryQuery;
@@ -40,6 +42,12 @@ import org.eclipse.mylyn.tasks.ui.TasksUi;
*/
public class PersonProposalProviderTest extends TestCase {
+ final private static Comparator<IContentProposal> CONTENT_COMPARATOR = new Comparator<IContentProposal>() {
+ public int compare(IContentProposal o1, IContentProposal o2) {
+ return o1.getContent().compareTo(o2.getContent());
+ }
+ };
+
@Override
protected void setUp() throws Exception {
TaskTestUtil.resetTaskListAndRepositories();
@@ -61,10 +69,68 @@ public class PersonProposalProviderTest extends TestCase {
assertEquals(0, result.length);
}
- public void testGetProposalsCurrentTask() {
+ public void testGetProposalsNullContents() throws Exception {
+ PersonProposalProvider provider = new PersonProposalProvider(MockRepositoryConnector.REPOSITORY_URL,
+ MockRepositoryConnector.CONNECTOR_KIND);
+
+ try {
+ provider.getProposals(null, 0);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidPosition() throws Exception {
+ PersonProposalProvider provider = new PersonProposalProvider(MockRepositoryConnector.REPOSITORY_URL,
+ MockRepositoryConnector.CONNECTOR_KIND);
+
+ try {
+ provider.getProposals("", -1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testGetProposalsTask() {
MockTask task = new MockTask(null, "1", null);
task.setOwner("foo");
PersonProposalProvider provider = new PersonProposalProvider(task, (TaskData) null);
+
+ assertProposalsForFoo(provider);
+ }
+
+ public void testGetProposalsTaskDataWithReporter() {
+ MockTask task = new MockTask(null, "1", null);
+ TaskData taskData = createMockTaskData();
+ taskData.getRoot().createMappedAttribute(TaskAttribute.USER_REPORTER).setValue("foo");
+ taskData.getRoot().getMappedAttribute(TaskAttribute.USER_REPORTER).getMetaData().setReadOnly(true);
+ PersonProposalProvider provider = new PersonProposalProvider(task, taskData);
+
+ assertProposalsForFoo(provider);
+ }
+
+ public void testGetProposalsTaskDataWithReporterPerson() {
+ MockTask task = new MockTask(null, "1", null);
+ TaskData taskData = createMockTaskData();
+ taskData.getRoot().createMappedAttribute(TaskAttribute.USER_REPORTER).setValue("foo");
+ taskData.getRoot().getMappedAttribute(TaskAttribute.USER_REPORTER).getMetaData().setReadOnly(true);
+ taskData.getRoot()
+ .getMappedAttribute(TaskAttribute.USER_REPORTER)
+ .getMetaData()
+ .setType(TaskAttribute.TYPE_PERSON);
+ PersonProposalProvider provider = new PersonProposalProvider(task, taskData);
+
+ assertProposalsForFoo(provider);
+ }
+
+ private TaskData createMockTaskData() {
+ return new TaskData(new TaskAttributeMapper(TaskTestUtil.createMockRepository()),
+ MockRepositoryConnector.CONNECTOR_KIND, MockRepositoryConnector.REPOSITORY_URL, "1");
+ }
+
+ static private void assertProposalsForFoo(PersonProposalProvider provider) {
IContentProposal[] result = provider.getProposals("", 0);
assertNotNull(result);
assertEquals(1, result.length);
@@ -85,6 +151,16 @@ public class PersonProposalProviderTest extends TestCase {
assertEquals("foo", result[0].getContent());
}
+ public void testGetProposalNoOwnerAndNoPerson() throws Exception {
+ PersonProposalProvider provider = new PersonProposalProvider(MockRepositoryConnector.REPOSITORY_URL,
+ MockRepositoryConnector.CONNECTOR_KIND);
+
+ IContentProposal[] result = provider.getProposals("", 0);
+
+ assertNotNull(result);
+ assertEquals(0, result.length);
+ }
+
public void testGetProposalsMultipleAddresses() {
IContentProposal[] result;
@@ -219,11 +295,7 @@ public class PersonProposalProviderTest extends TestCase {
PersonProposalProvider provider = new PersonProposalProvider(task1, (TaskData) null, users);
IContentProposal[] result = provider.getProposals("", 0);
- Arrays.sort(result, new Comparator<IContentProposal>() {
- public int compare(IContentProposal o1, IContentProposal o2) {
- return o1.getContent().compareTo(o2.getContent());
- }
- });
+ Arrays.sort(result, CONTENT_COMPARATOR);
assertNotNull(result);
assertEquals(4, result.length);
assertEquals("11", result[0].getContent());
@@ -232,53 +304,33 @@ public class PersonProposalProviderTest extends TestCase {
assertEquals("33", result[3].getContent());
result = provider.getProposals("f", 1);
- Arrays.sort(result, new Comparator<IContentProposal>() {
- public int compare(IContentProposal o1, IContentProposal o2) {
- return o1.getContent().compareTo(o2.getContent());
- }
- });
+ Arrays.sort(result, CONTENT_COMPARATOR);
assertNotNull(result);
assertEquals(2, result.length);
assertEquals("11", result[0].getContent());
assertEquals("33", result[1].getContent());
result = provider.getProposals("b", 1);
- Arrays.sort(result, new Comparator<IContentProposal>() {
- public int compare(IContentProposal o1, IContentProposal o2) {
- return o1.getContent().compareTo(o2.getContent());
- }
- });
+ Arrays.sort(result, CONTENT_COMPARATOR);
assertNotNull(result);
assertEquals(2, result.length);
assertEquals("21", result[0].getContent());
assertEquals("22", result[1].getContent());
result = provider.getProposals("1", 1);
- Arrays.sort(result, new Comparator<IContentProposal>() {
- public int compare(IContentProposal o1, IContentProposal o2) {
- return o1.getContent().compareTo(o2.getContent());
- }
- });
+ Arrays.sort(result, CONTENT_COMPARATOR);
assertNotNull(result);
assertEquals(1, result.length);
assertEquals("11", result[0].getContent());
result = provider.getProposals("3", 1);
- Arrays.sort(result, new Comparator<IContentProposal>() {
- public int compare(IContentProposal o1, IContentProposal o2) {
- return o1.getContent().compareTo(o2.getContent());
- }
- });
+ Arrays.sort(result, CONTENT_COMPARATOR);
assertNotNull(result);
assertEquals(1, result.length);
assertEquals("33", result[0].getContent());
result = provider.getProposals("2", 1);
- Arrays.sort(result, new Comparator<IContentProposal>() {
- public int compare(IContentProposal o1, IContentProposal o2) {
- return o1.getContent().compareTo(o2.getContent());
- }
- });
+ Arrays.sort(result, CONTENT_COMPARATOR);
assertNotNull(result);
assertEquals(2, result.length);
assertEquals("21", result[0].getContent());
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java
index d285179fa..379a2bb32 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java
@@ -23,6 +23,7 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.fieldassist.IContentProposal;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
@@ -103,9 +104,8 @@ public class PersonProposalProvider implements IContentProposalProvider {
}
public IContentProposal[] getProposals(String contents, int position) {
- if (contents == null) {
- throw new IllegalArgumentException();
- }
+ Assert.isLegal(contents != null);
+ Assert.isLegal(position >= 0);
int leftSeparator = getIndexOfLeftSeparator(contents, position);
int rightSeparator = getIndexOfRightSeparator(contents, position);

Back to the top