aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlav Lenz2012-10-25 10:12:02 (EDT)
committerOlav Lenz2012-11-01 10:10:09 (EDT)
commit30dc229bcf48b4561acf00bc9990b00576545fff (patch)
treeb06164d156110fd6bc0658655abf8a7e1be17ab3
parent81fcdb169da4e5b45ea9b7535829b45353ba6bde (diff)
downloadorg.eclipse.recommenders-30dc229bcf48b4561acf00bc9990b00576545fff.zip
org.eclipse.recommenders-30dc229bcf48b4561acf00bc9990b00576545fff.tar.gz
org.eclipse.recommenders-30dc229bcf48b4561acf00bc9990b00576545fff.tar.bz2
[Extdoc] add tests for Drag'n'Droprefs/changes/71/8371/6
-rw-r--r--plugins/org.eclipse.recommenders.extdoc.rcp/src/org/eclipse/recommenders/internal/extdoc/rcp/ui/ExtdocView.java5
-rw-r--r--tests/org.eclipse.recommenders.tests.extdoc.rcp/src/org/eclipse/recommenders/tests/extdoc/ExtdocDnDTest.java121
2 files changed, 126 insertions, 0 deletions
diff --git a/plugins/org.eclipse.recommenders.extdoc.rcp/src/org/eclipse/recommenders/internal/extdoc/rcp/ui/ExtdocView.java b/plugins/org.eclipse.recommenders.extdoc.rcp/src/org/eclipse/recommenders/internal/extdoc/rcp/ui/ExtdocView.java
index ab6f724..1b4ab95 100644
--- a/plugins/org.eclipse.recommenders.extdoc.rcp/src/org/eclipse/recommenders/internal/extdoc/rcp/ui/ExtdocView.java
+++ b/plugins/org.eclipse.recommenders.extdoc.rcp/src/org/eclipse/recommenders/internal/extdoc/rcp/ui/ExtdocView.java
@@ -274,6 +274,11 @@ public class ExtdocView extends ViewPart {
move(oldIndex, newIndex, MOVE_BEFORE);
}
+ @VisibleForTesting
+ public List<ExtdocProvider> getProviderRanking() {
+ return providerRanking;
+ }
+
private void createContentArea() {
scrollable = new ScrolledComposite(sash, SWT.H_SCROLL | SWT.V_SCROLL);
scrollable.getVerticalBar().setIncrement(20);
diff --git a/tests/org.eclipse.recommenders.tests.extdoc.rcp/src/org/eclipse/recommenders/tests/extdoc/ExtdocDnDTest.java b/tests/org.eclipse.recommenders.tests.extdoc.rcp/src/org/eclipse/recommenders/tests/extdoc/ExtdocDnDTest.java
new file mode 100644
index 0000000..68a3cb0
--- /dev/null
+++ b/tests/org.eclipse.recommenders.tests.extdoc.rcp/src/org/eclipse/recommenders/tests/extdoc/ExtdocDnDTest.java
@@ -0,0 +1,121 @@
+/**
+ * Copyright (c) 2010, 2012 Darmstadt University of Technology.
+ * 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:
+ * Patrick Gottschaemmer, Olav Lenz - initial tests
+ */
+package org.eclipse.recommenders.tests.extdoc;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.recommenders.extdoc.rcp.providers.ExtdocProvider;
+import org.eclipse.recommenders.internal.extdoc.rcp.ui.ExtdocPreferences;
+import org.eclipse.recommenders.internal.extdoc.rcp.ui.ExtdocView;
+import org.eclipse.recommenders.internal.extdoc.rcp.ui.SubscriptionManager;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+import com.google.common.eventbus.EventBus;
+
+public class ExtdocDnDTest {
+
+ private ExtdocView view;
+ private List<ExtdocProvider> defaultOrder;
+ private ExtdocProvider provider0;
+ private ExtdocProvider provider1;
+ private ExtdocProvider provider2;
+ private ExtdocProvider provider3;
+ private ExtdocProvider provider4;
+
+ @Before
+ public void setup() {
+ EventBus bus = mock(EventBus.class);
+ SubscriptionManager subManger = mock(SubscriptionManager.class);
+
+ provider0 = mock(ExtdocProvider.class);
+ provider1 = mock(ExtdocProvider.class);
+ provider2 = mock(ExtdocProvider.class);
+ provider3 = mock(ExtdocProvider.class);
+ provider4 = mock(ExtdocProvider.class);
+
+ List<ExtdocProvider> providers = Lists.newArrayList(provider0, provider1, provider2, provider3, provider4);
+
+ defaultOrder = new LinkedList<ExtdocProvider>(providers);
+
+ ExtdocPreferences preferences = mock(ExtdocPreferences.class);
+ view = new ExtdocView(bus, subManger, providers, preferences);
+ }
+
+ @Test
+ public void moveOnItselfBefore() {
+ view.moveBefore(1, 1);
+
+ assertEquals(defaultOrder, view.getProviderRanking());
+ }
+
+ @Test
+ public void moveOnItselfAfter() {
+ view.moveAfter(0, 0);
+
+ assertEquals(defaultOrder, view.getProviderRanking());
+ }
+
+ @Test
+ public void moveAfterNoChange() {
+ view.moveAfter(3, 2);
+
+ assertEquals(defaultOrder, view.getProviderRanking());
+ }
+
+ @Test
+ public void moveBeforeNoChange() {
+ view.moveBefore(2, 3);
+
+ assertEquals(defaultOrder, view.getProviderRanking());
+ }
+
+ @Test
+ public void moveBeforeTop() {
+ view.moveBefore(4, 0);
+
+ List<ExtdocProvider> expectedOrder = Lists.newArrayList(provider4, provider0, provider1, provider2, provider3);
+
+ assertEquals(expectedOrder, view.getProviderRanking());
+ }
+
+ @Test
+ public void moveAfterTop() {
+ view.moveAfter(2, 0);
+
+ List<ExtdocProvider> expectedOrder = Lists.newArrayList(provider0, provider2, provider1, provider3, provider4);
+
+ assertEquals(expectedOrder, view.getProviderRanking());
+ }
+
+ @Test
+ public void moveBeforeBottom() {
+ view.moveBefore(2, 4);
+
+ List<ExtdocProvider> expectedOrder = Lists.newArrayList(provider0, provider1, provider3, provider2, provider4);
+
+ assertEquals(expectedOrder, view.getProviderRanking());
+ }
+
+ @Test
+ public void moveAfterBottom() {
+ view.moveAfter(2, 4);
+
+ List<ExtdocProvider> expectedOrder = Lists.newArrayList(provider0, provider1, provider3, provider4, provider2);
+
+ assertEquals(expectedOrder, view.getProviderRanking());
+ }
+} \ No newline at end of file