summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2014-04-15 19:10:43 (EDT)
committerSam Davis2014-04-25 13:13:36 (EDT)
commit48191970115a3e5fedc002932e3de5c4983a8cb4 (patch)
tree7abd6244b3aa2b04b9711e163371745307f71c4e
parent0ad5c32983074bc30a473d2ccb0355773ea46aaa (diff)
downloadorg.eclipse.mylyn.reviews-48191970115a3e5fedc002932e3de5c4983a8cb4.zip
org.eclipse.mylyn.reviews-48191970115a3e5fedc002932e3de5c4983a8cb4.tar.gz
org.eclipse.mylyn.reviews-48191970115a3e5fedc002932e3de5c4983a8cb4.tar.bz2
Refactor tests: extract observer/consumer boilerplate to utility methodsrefs/changes/90/25090/3
Change-Id: Ic6b056b08694afc371e5a0cd25cf1403befdeaa5 Signed-off-by: Sam Davis <sam.davis@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java12
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java61
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserver.java3
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserverConsumer.java90
4 files changed, 120 insertions, 46 deletions
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java
index 1c1c3c2..94b7086 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java
@@ -15,6 +15,7 @@ import static org.eclipse.mylyn.gerrit.tests.core.client.rest.IsEmpty.empty;
import static org.eclipse.mylyn.internal.gerrit.core.client.rest.ApprovalUtil.CRVW;
import static org.eclipse.mylyn.internal.gerrit.core.client.rest.ApprovalUtil.VRIF;
import static org.eclipse.mylyn.internal.gerrit.core.client.rest.ApprovalUtil.toNameWithDash;
+import static org.eclipse.mylyn.internal.gerrit.core.remote.TestRemoteObserverConsumer.retrieveForRemoteKey;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
@@ -57,7 +58,6 @@ import org.eclipse.mylyn.reviews.core.model.IReviewerEntry;
import org.eclipse.mylyn.reviews.core.model.IUser;
import org.eclipse.mylyn.reviews.core.model.RequirementStatus;
import org.eclipse.mylyn.reviews.core.model.ReviewStatus;
-import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfConsumer;
import org.junit.Test;
import com.google.gerrit.common.data.ApprovalDetail;
@@ -191,13 +191,9 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
String resultIdDep1 = StringUtils.trimToEmpty(StringUtils.substringAfterLast(resultDep1.push.getMessages(), "/"));
assertThat("Bad Push: " + resultDep1.push.getMessages(), resultIdDep1.length(), greaterThan(0));
- TestRemoteObserver<IRepository, IReview, String, Date> reviewListenerDep1 = new TestRemoteObserver<IRepository, IReview, String, Date>(
- reviewHarness.provider.getReviewFactory());
- RemoteEmfConsumer<IRepository, IReview, String, GerritChange, String, Date> consumerDep1 = reviewHarness.provider.getReviewFactory()
- .getConsumerForRemoteKey(reviewHarness.getRepository(), resultIdDep1);
- consumerDep1.addObserver(reviewListenerDep1);
- consumerDep1.retrieve(false);
- reviewListenerDep1.waitForResponse();
+ TestRemoteObserverConsumer<IRepository, IReview, String, GerritChange, String, Date> consumerDep1 //
+ = retrieveForRemoteKey(reviewHarness.provider.getReviewFactory(), reviewHarness.getRepository(), resultIdDep1,
+ true);
IReview reviewDep1 = consumerDep1.getModelObject();
assertThat(reviewDep1.getParents().size(), is(1));
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java
index 2bfd5af..50bebd1 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java
@@ -11,6 +11,8 @@
package org.eclipse.mylyn.internal.gerrit.core.remote;
+import static org.eclipse.mylyn.internal.gerrit.core.remote.TestRemoteObserverConsumer.retrieveForLocalKey;
+import static org.eclipse.mylyn.internal.gerrit.core.remote.TestRemoteObserverConsumer.retrieveForRemoteKey;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
@@ -30,7 +32,6 @@ import org.eclipse.mylyn.reviews.core.model.IFileVersion;
import org.eclipse.mylyn.reviews.core.model.IReview;
import org.eclipse.mylyn.reviews.core.model.IReviewItem;
import org.eclipse.mylyn.reviews.core.model.IReviewItemSet;
-import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfConsumer;
import org.junit.Test;
import com.google.gerrit.common.data.PatchSetDetail;
@@ -60,26 +61,12 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
assertThat(getReview().getSets().size(), is(3));
IReviewItemSet testPatchSet = getReview().getSets().get(2);
- RemoteEmfConsumer<IReview, IReviewItemSet, String, PatchSetDetail, PatchSetDetail, String> itemSetConsumer = reviewHarness.provider.getReviewItemSetFactory()
- .getConsumerForLocalKey(getReview(), "3");
- TestRemoteObserver<IReview, IReviewItemSet, String, String> itemSetObserver = new TestRemoteObserver<IReview, IReviewItemSet, String, String>(
- reviewHarness.provider.getReviewItemSetFactory());
- itemSetConsumer.addObserver(itemSetObserver);
- itemSetConsumer.retrieve(false);
- itemSetObserver.waitForResponse(false);
- PatchSetDetail detail = itemSetConsumer.getRemoteObject();
+ PatchSetDetail detail = retrievePatchSetDetail("3");
assertThat(detail.getInfo().getKey().get(), is(3));
- PatchSetContentIdRemoteFactory patchFactory = reviewHarness.provider.getReviewItemSetContentFactory();
List<IFileItem> fileItems = testPatchSet.getItems();
assertThat(fileItems.size(), is(0));
- TestRemoteObserver<IReviewItemSet, List<IFileItem>, String, Long> patchSetListener = new TestRemoteObserver<IReviewItemSet, List<IFileItem>, String, Long>(
- patchFactory);
- RemoteEmfConsumer<IReviewItemSet, List<IFileItem>, String, PatchSetContent, String, Long> patchSetConsumer = patchFactory.getConsumerForRemoteKey(
- testPatchSet, "3");
- patchSetConsumer.addObserver(patchSetListener);
- patchSetConsumer.retrieve(false);
- patchSetListener.waitForResponse();
+ retrievePatchSetContents(testPatchSet);
assertThat(fileItems.size(), is(6));
for (IReviewItem fileItem : fileItems) {
@@ -124,25 +111,12 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.commitAndPush(command2);
reviewHarness.consumer.retrieve(false);
reviewHarness.listener.waitForResponse();
- RemoteEmfConsumer<IReview, IReviewItemSet, String, PatchSetDetail, PatchSetDetail, String> itemSetConsumer = reviewHarness.provider.getReviewItemSetFactory()
- .getConsumerForLocalKey(getReview(), "2");
- TestRemoteObserver<IReview, IReviewItemSet, String, String> itemSetObserver = new TestRemoteObserver<IReview, IReviewItemSet, String, String>(
- reviewHarness.provider.getReviewItemSetFactory());
- itemSetConsumer.addObserver(itemSetObserver);
- itemSetConsumer.retrieve(false);
- itemSetObserver.waitForResponse(false);
- PatchSetDetail detail = itemSetConsumer.getRemoteObject();
+ PatchSetDetail detail = retrievePatchSetDetail("2");
assertThat(detail.getInfo().getKey().get(), is(2));
IReviewItemSet testPatchSet = getReview().getSets().get(1);
- PatchSetContentIdRemoteFactory patchFactory = reviewHarness.provider.getReviewItemSetContentFactory();
- TestRemoteObserver<IReviewItemSet, List<IFileItem>, String, Long> patchSetListener = new TestRemoteObserver<IReviewItemSet, List<IFileItem>, String, Long>(
- patchFactory);
- RemoteEmfConsumer<IReviewItemSet, List<IFileItem>, String, PatchSetContent, String, Long> patchSetConsumer = patchFactory.getConsumerForRemoteKey(
- testPatchSet, "2");
- patchSetConsumer.addObserver(patchSetListener);
- patchSetConsumer.retrieve(false);
- patchSetListener.waitForResponse();
+ TestRemoteObserverConsumer<IReviewItemSet, List<IFileItem>, String, PatchSetContent, String, Long> patchSetObserver //
+ = retrievePatchSetContents(testPatchSet);
IFileItem commentFile = testPatchSet.getItems().get(1);
assertThat(commentFile.getName(), is("testComments.txt"));
@@ -151,8 +125,8 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
String id = commentFile.getReference();
reviewHarness.client.saveDraft(Patch.Key.parse(id), "Line 2 Comment", 2, (short) 1, null,
new NullProgressMonitor());
- patchSetConsumer.retrieve(false);
- patchSetListener.waitForResponse();
+ patchSetObserver.retrieve(false);
+ patchSetObserver.waitForResponse();
commentFile = testPatchSet.getItems().get(1);
List<IComment> allComments = commentFile.getAllComments();
@@ -165,8 +139,8 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.client.publishComments(reviewHarness.shortId, 2, "Submit Comments",
Collections.<ApprovalCategoryValue.Id> emptySet(), new NullProgressMonitor());
- patchSetConsumer.retrieve(false);
- patchSetListener.waitForResponse();
+ patchSetObserver.retrieve(false);
+ patchSetObserver.waitForResponse();
allComments = commentFile.getAllComments();
assertThat(allComments.size(), is(1));
fileComment = allComments.get(0);
@@ -203,4 +177,17 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
assertThat(content.getPatchScript(commitMsgPatchKey), notNullValue());
assertThat(content.getPatchScript(testFilePatchKey), notNullValue());
}
+
+ private PatchSetDetail retrievePatchSetDetail(String patchSetId) {
+ TestRemoteObserverConsumer<IReview, IReviewItemSet, String, PatchSetDetail, PatchSetDetail, String> itemSetObserver //
+ = retrieveForLocalKey(reviewHarness.provider.getReviewItemSetFactory(), getReview(), patchSetId, false);
+ PatchSetDetail detail = itemSetObserver.getRemoteObject();
+ return detail;
+ }
+
+ private TestRemoteObserverConsumer<IReviewItemSet, List<IFileItem>, String, PatchSetContent, String, Long> retrievePatchSetContents(
+ IReviewItemSet patchSet) {
+ return retrieveForRemoteKey(reviewHarness.provider.getReviewItemSetContentFactory(), patchSet,
+ patchSet.getId(), true);
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserver.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserver.java
index cb7f249..d995ba1 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserver.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserver.java
@@ -19,7 +19,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.mylyn.reviews.core.spi.remote.emf.AbstractRemoteEmfFactory;
import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfObserver;
-final class TestRemoteObserver<P extends EObject, T, L, C> extends RemoteEmfObserver<P, T, L, C> {
+class TestRemoteObserver<P extends EObject, T, L, C> extends RemoteEmfObserver<P, T, L, C> {
static final int TEST_TIMEOUT = 15000;
@@ -86,4 +86,5 @@ final class TestRemoteObserver<P extends EObject, T, L, C> extends RemoteEmfObse
updated = 0;
}
}
+
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserverConsumer.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserverConsumer.java
new file mode 100644
index 0000000..df8d22b
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserverConsumer.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.internal.gerrit.core.remote;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.mylyn.reviews.core.spi.remote.emf.AbstractRemoteEmfFactory;
+import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfConsumer;
+import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfObserver;
+
+/**
+ * Extends TestRemoteObserver so that it wraps a consumer and provides delegate methods for common operations.
+ */
+public class TestRemoteObserverConsumer<EParentObject extends EObject, EObjectType, LocalKey, Remote, RemoteKey, //
+ObjectCurrentType> extends TestRemoteObserver<EParentObject, EObjectType, LocalKey, ObjectCurrentType> {
+
+ RemoteEmfConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> consumer;
+
+ public static <EParentObject extends EObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> //
+ TestRemoteObserverConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> //
+ retrieveForLocalKey(
+ AbstractRemoteEmfFactory<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> factory,
+ EParentObject item, LocalKey localKey, boolean expectUpdate) {
+ RemoteEmfConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> consumer //
+ = factory.getConsumerForLocalKey(item, localKey);
+ return retrieve(factory, consumer, expectUpdate);
+ }
+
+ public static <EParentObject extends EObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> //
+ TestRemoteObserverConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> //
+ retrieveForRemoteKey(
+ AbstractRemoteEmfFactory<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> factory,
+ EParentObject item, RemoteKey remoteKey, boolean expectUpdate) {
+ RemoteEmfConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> consumer //
+ = factory.getConsumerForRemoteKey(item, remoteKey);
+ return retrieve(factory, consumer, expectUpdate);
+ }
+
+ private static <EParentObject extends EObject, EObjectType, RemoteKey, ObjectCurrentType, LocalKey, Remote> //
+ TestRemoteObserverConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> retrieve(
+ AbstractRemoteEmfFactory<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> factory,
+ RemoteEmfConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> consumer,
+ boolean expectUpdate) {
+ TestRemoteObserverConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> observer //
+ = create(factory, consumer);
+ consumer.addObserver(observer);
+ consumer.retrieve(false);
+ observer.waitForResponse(expectUpdate);
+ return observer;
+ }
+
+ public static <EParentObject extends EObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> //
+ TestRemoteObserverConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> //
+ create(AbstractRemoteEmfFactory<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> factory,
+ RemoteEmfConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> consumer) {
+ return new TestRemoteObserverConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType>(
+ factory, consumer);
+ }
+
+ public TestRemoteObserverConsumer(
+ AbstractRemoteEmfFactory<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> factory,
+ RemoteEmfConsumer<EParentObject, EObjectType, LocalKey, Remote, RemoteKey, ObjectCurrentType> consumer) {
+ super(factory);
+ this.consumer = consumer;
+ }
+
+ public void addObserver(RemoteEmfObserver<EParentObject, EObjectType, LocalKey, ObjectCurrentType> observer) {
+ consumer.addObserver(observer);
+ }
+
+ public void retrieve(boolean force) {
+ consumer.retrieve(force);
+ }
+
+ public Remote getRemoteObject() {
+ return consumer.getRemoteObject();
+ }
+
+ public EObjectType getModelObject() {
+ return consumer.getModelObject();
+ }
+}