Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaxsun McCarthy Huggan2015-09-04 18:54:24 -0400
committerGerrit Code Review @ Eclipse.org2015-09-09 14:44:21 -0400
commit95141fe232ccd52b7eff54433996996d4fbcf13b (patch)
tree730ebbcff53c109184f7a1a660189b802a2baf3f
parentcbd98a2f79e98d0bccff707a7536eeedd376fa3f (diff)
downloadorg.eclipse.mylyn.tasks-95141fe232ccd52b7eff54433996996d4fbcf13b.tar.gz
org.eclipse.mylyn.tasks-95141fe232ccd52b7eff54433996996d4fbcf13b.tar.xz
org.eclipse.mylyn.tasks-95141fe232ccd52b7eff54433996996d4fbcf13b.zip
476680: AbstractRepositorySettingsPage doesn't udpate brand when
specified brand is null Change-Id: I2f003ceba1ea9c5b46adabe301dbd8302eb80fc9 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=476680 Signed-off-by: Jaxsun McCarthy Huggan <jaxsunm@gmail.com>
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java72
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorUi.java6
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositorySettingsPage.java93
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java61
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizard.java6
5 files changed, 155 insertions, 83 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java
index 3486e5325..cfef42850 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java
@@ -11,23 +11,19 @@
package org.eclipse.mylyn.tasks.tests;
-import junit.framework.TestCase;
-
-import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
-import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnectorUi;
-import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositorySettingsPage;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
+import junit.framework.TestCase;
+
/**
* @author Steffen Pingel
*/
@@ -269,66 +265,4 @@ public class RepositorySettingsPageTest extends TestCase {
}
- private class MockRepositorySettingsPage extends AbstractRepositorySettingsPage {
-
- public MockRepositorySettingsPage(TaskRepository taskRepository) {
- super("title", "summary", taskRepository);
- }
-
- public MockRepositorySettingsPage(TaskRepository taskRepository, AbstractRepositoryConnector connector) {
- super("title", "summary", taskRepository, connector);
- }
-
- @Override
- protected void createAdditionalControls(Composite parent) {
- // ignore
- }
-
- @Override
- protected boolean isValidUrl(String url) {
- return super.isValidUrl(url);
- }
-
- @Override
- protected void validateSettings() {
- // ignore
- }
-
- Button getAnonymousButton() {
- return anonymousButton;
- }
-
- StringFieldEditor getUserNameEditor() {
- return repositoryUserNameEditor;
- }
-
- StringFieldEditor getPasswordEditor() {
- return repositoryPasswordEditor;
- }
-
- Composite getParent() {
- return compositeContainer;
- }
-
- @Override
- protected Validator getValidator(TaskRepository repository) {
- // ignore
- return null;
- }
-
- @Override
- public String getConnectorKind() {
- return MockRepositoryConnector.CONNECTOR_KIND;
- }
-
- public StringFieldEditor getRepositoryUserNameEditor() {
- return repositoryUserNameEditor;
- }
-
- public StringFieldEditor getRepositoryPasswordEditor() {
- return repositoryPasswordEditor;
- }
-
- }
-
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorUi.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorUi.java
index ffedf9be3..d6fc3af65 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorUi.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorUi.java
@@ -41,8 +41,7 @@ public class MockRepositoryConnectorUi extends AbstractRepositoryConnectorUi {
@Override
public ITaskRepositoryPage getSettingsPage(TaskRepository taskRepository) {
- // ignore
- return null;
+ return new MockRepositorySettingsPage(taskRepository);
}
@Override
@@ -68,7 +67,8 @@ public class MockRepositoryConnectorUi extends AbstractRepositoryConnectorUi {
List<IHyperlink> links = new ArrayList<IHyperlink>();
Matcher m = HYPERLINK_PATTERN.matcher(text);
while (m.find()) {
- links.add(new TaskHyperlink(new Region(textOffset + m.start(), m.end() - m.start()), repository, m.group()));
+ links.add(
+ new TaskHyperlink(new Region(textOffset + m.start(), m.end() - m.start()), repository, m.group()));
}
return links.toArray(new IHyperlink[0]);
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositorySettingsPage.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositorySettingsPage.java
new file mode 100644
index 000000000..618558d10
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositorySettingsPage.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.connector;
+
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
+public class MockRepositorySettingsPage extends AbstractRepositorySettingsPage {
+
+ private String brand;
+
+ public MockRepositorySettingsPage(TaskRepository taskRepository) {
+ super("title", "summary", taskRepository);
+ }
+
+ public MockRepositorySettingsPage(TaskRepository taskRepository, AbstractRepositoryConnector connector) {
+ super("title", "summary", taskRepository, connector);
+ }
+
+ @Override
+ protected void createAdditionalControls(Composite parent) {
+ // ignore
+ }
+
+ @Override
+ public boolean isValidUrl(String url) {
+ return super.isValidUrl(url);
+ }
+
+ @Override
+ protected void validateSettings() {
+ // ignore
+ }
+
+ public Button getAnonymousButton() {
+ return anonymousButton;
+ }
+
+ public StringFieldEditor getUserNameEditor() {
+ return repositoryUserNameEditor;
+ }
+
+ public StringFieldEditor getPasswordEditor() {
+ return repositoryPasswordEditor;
+ }
+
+ public Composite getParent() {
+ return compositeContainer;
+ }
+
+ @Override
+ protected Validator getValidator(TaskRepository repository) {
+ // ignore
+ return null;
+ }
+
+ @Override
+ public String getConnectorKind() {
+ return MockRepositoryConnector.CONNECTOR_KIND;
+ }
+
+ public StringFieldEditor getRepositoryUserNameEditor() {
+ return repositoryUserNameEditor;
+ }
+
+ public StringFieldEditor getRepositoryPasswordEditor() {
+ return repositoryPasswordEditor;
+ }
+
+ @Override
+ public void setBrand(String brand) {
+ super.setBrand(brand);
+ this.brand = brand;
+ }
+
+ public String getBrand() {
+ return brand;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java
index 23ea56b83..2629a16ba 100644
--- a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java
@@ -14,28 +14,71 @@ package org.eclipse.mylyn.internal.tasks.ui.wizards;
import static org.eclipse.mylyn.internal.tasks.ui.wizards.Messages.SelectRepositoryConnectorPage_Select_a_task_repository_type;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import org.eclipse.mylyn.internal.tasks.ui.ConnectorBrand;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositorySettingsPage;
+import org.junit.Before;
import org.junit.Test;
public class NewRepositoryWizardTest {
+ private NewRepositoryWizard wizard;
+
+ @Before
+ public void setUp() {
+ wizard = new NewRepositoryWizard();
+ wizard.addPages();
+ }
+
@Test
public void testGetNextPageIWizardPage() {
- NewRepositoryWizard wizard = new NewRepositoryWizard(null);
- wizard.addPages();
- SelectRepositoryConnectorPage page = (SelectRepositoryConnectorPage) wizard.getPage(SelectRepositoryConnectorPage_Select_a_task_repository_type);
+ SelectRepositoryConnectorPage page = (SelectRepositoryConnectorPage) wizard
+ .getPage(SelectRepositoryConnectorPage_Select_a_task_repository_type);
page.setConnectorBrand(new ConnectorBrand(new MockRepositoryConnector(), "org.mylyn"));
wizard.getNextPage(null);
assertNull(wizard.getBrand());
- try {
- wizard.getNextPage(page);
- } catch (RuntimeException e) {
- assertTrue(e.getMessage().startsWith("The connector implementation is incomplete"));
- }
+ wizard.getNextPage(page);
assertEquals("org.mylyn", wizard.getBrand());
}
+
+ @Test
+ public void testSetsBrandOnSettingsPage() {
+ MockRepositorySettingsPage settingsPage = navigateWithBrands("org.mylyn");
+ assertEquals("org.mylyn", settingsPage.getBrand());
+ }
+
+ public void testSetsBrandOnSettingsPageNoBrand() {
+ MockRepositorySettingsPage settingsPage = navigateWithBrands((String) null);
+ assertEquals("", settingsPage.getBrand());
+ }
+
+ @Test
+ public void testSetsBrandOnSettingsPageBrandChangeToNull() {
+ MockRepositorySettingsPage settingsPage = navigateWithBrands("org.mylyn", null);
+ assertEquals("", settingsPage.getBrand());
+ }
+
+ @Test
+ public void testSetsBrandOnSettingsPageBrandChangeFromNull() {
+ MockRepositorySettingsPage settingsPage = navigateWithBrands(null, "org.mylyn");
+ assertEquals("org.mylyn", settingsPage.getBrand());
+ }
+
+ @Test
+ public void testSetsBrandOnSettingsPageBrandChange() {
+ MockRepositorySettingsPage settingsPage = navigateWithBrands("org.eclipse", "org.mylyn");
+ assertEquals("org.mylyn", settingsPage.getBrand());
+ }
+
+ private MockRepositorySettingsPage navigateWithBrands(String... brands) {
+ SelectRepositoryConnectorPage selectionPage = (SelectRepositoryConnectorPage) wizard
+ .getPage(SelectRepositoryConnectorPage_Select_a_task_repository_type);
+ for (String brand : brands) {
+ selectionPage.setConnectorBrand(new ConnectorBrand(new MockRepositoryConnector(), brand));
+ wizard.getNextPage(selectionPage);
+ }
+ return (MockRepositorySettingsPage) wizard.getNextPage(selectionPage);
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizard.java
index c8b43b67d..ff541ed71 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizard.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizard.java
@@ -36,6 +36,8 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
+import com.google.common.base.Strings;
+
/**
* @author Mik Kersten
* @author Steffen Pingel
@@ -149,8 +151,8 @@ public class NewRepositoryWizard extends Wizard implements INewWizard {
settingsPage.setWizard(this);
lastConnectorKind = connector.getConnectorKind();
}
- if (settingsPage instanceof AbstractRepositorySettingsPage && brand != null) {
- ((AbstractRepositorySettingsPage) settingsPage).setBrand(brand);
+ if (settingsPage instanceof AbstractRepositorySettingsPage) {
+ ((AbstractRepositorySettingsPage) settingsPage).setBrand(Strings.nullToEmpty(brand));
}
}

Back to the top