summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2014-04-15 16:31:19 (EDT)
committerTomasz Zarna2014-04-16 18:45:56 (EDT)
commit4cfb9d394152c919c09fd9072af13f2cd096e2bb (patch)
tree2e1483e2801f27bf237cdc86ec01f3b79877b823
parentab3a3f7f92eb08ab55600cdd9c7fa4ddeb3319a8 (diff)
downloadorg.eclipse.mylyn.reviews-4cfb9d394152c919c09fd9072af13f2cd096e2bb.zip
org.eclipse.mylyn.reviews-4cfb9d394152c919c09fd9072af13f2cd096e2bb.tar.gz
org.eclipse.mylyn.reviews-4cfb9d394152c919c09fd9072af13f2cd096e2bb.tar.bz2
Refactor tests: remove need to count responses and pass torefs/changes/89/25089/2
waitForResponse Change-Id: Iba5a8f834612ddab2c0bd406f0b69b7ad3de2323 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.java26
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java16
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/ReviewHarness.java2
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/TestRemoteObserver.java57
4 files changed, 57 insertions, 44 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 27ff212..ae7a74a 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
@@ -84,7 +84,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.client.publishComments(reviewHarness.shortId, 1, message2,
Collections.<ApprovalCategoryValue.Id> emptySet(), null);
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
List<IComment> comments = getReview().getComments();
int offset = getCommentOffset();
assertThat(comments.size(), is(offset + 2));
@@ -118,7 +118,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.addFile("testFile2.txt");
reviewHarness.commitAndPush(command2);
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
List<IReviewItemSet> items = getReview().getSets();
assertThat(items.size(), is(2));
IReviewItemSet patchSet2 = items.get(1);
@@ -154,7 +154,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
new HashSet<ApprovalCategoryValue.Id>(Collections.singleton(CRVW.getValue((short) 1).getId())),
new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertThat(getReview().getReviewerApprovals().size(), is(1));
Entry<IUser, IReviewerEntry> reviewerEntry = getReview().getReviewerApprovals().entrySet().iterator().next();
Map<IApprovalType, Integer> reviewerApprovals = reviewerEntry.getValue().getApprovals();
@@ -197,7 +197,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
.getConsumerForRemoteKey(reviewHarness.getRepository(), resultIdDep1);
consumerDep1.addObserver(reviewListenerDep1);
consumerDep1.retrieve(false);
- reviewListenerDep1.waitForResponse(1, 1);
+ reviewListenerDep1.waitForResponse();
IReview reviewDep1 = consumerDep1.getModelObject();
assertThat(reviewDep1.getParents().size(), is(1));
@@ -208,7 +208,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
assertThat(parentChange.getModificationDate().getTime(), is(getReview().getModificationDate().getTime()));
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertThat(getReview().getChildren().size(), is(1));
IChange childChange = getReview().getChildren().get(0);
//Not expected to be same instance
@@ -224,7 +224,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
ChangeDetail changeDetail = reviewHarness.client.abandon(reviewHarness.shortId, 1, message1,
new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertThat(changeDetail, notNullValue());
assertThat(changeDetail.getChange().getStatus(), is(Status.ABANDONED));
@@ -249,12 +249,12 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
String message1 = "abandon, time: " + System.currentTimeMillis();
reviewHarness.client.abandon(reviewHarness.shortId, 1, message1, new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
String message2 = "restore, time: " + System.currentTimeMillis();
reviewHarness.client.restore(reviewHarness.shortId, 1, message2, new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(3, 3);
+ reviewHarness.listener.waitForResponse();
assertThat(getReview().getState(), is(ReviewStatus.NEW));
List<IComment> comments = getReview().getComments();
@@ -305,7 +305,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
ReviewerResult reviewerResult = reviewHarness.client.addReviewers(reviewHarness.shortId,
Collections.<String> emptyList(), new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertThat(reviewerResult, notNullValue());
assertThat(reviewerResult.getErrors().isEmpty(), is(true));
@@ -320,7 +320,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
ReviewerResult reviewerResult = reviewHarness.client.addReviewers(reviewHarness.shortId, reviewers,
new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertThat(reviewerResult, notNullValue());
assertThat(reviewerResult.getErrors().size(), is(1));
@@ -337,7 +337,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
ReviewerResult reviewerResult = reviewHarness.client.addReviewers(reviewHarness.shortId, reviewers,
new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertReviewerResult(reviewerResult, "foo");
}
@@ -350,7 +350,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
ReviewerResult reviewerResult = reviewHarness.client.addReviewers(reviewHarness.shortId, reviewers,
new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertReviewerResult(reviewerResult, null);
}
@@ -362,7 +362,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
ReviewerResult reviewerResult = reviewHarness.client.addReviewers(reviewHarness.shortId, reviewers,
new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertReviewerResult(reviewerResult, null);
}
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 c0da123..2bfd5af 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
@@ -56,7 +56,7 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.addFile("testFile5.txt");
reviewHarness.commitAndPush(command3);
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ reviewHarness.listener.waitForResponse();
assertThat(getReview().getSets().size(), is(3));
IReviewItemSet testPatchSet = getReview().getSets().get(2);
@@ -66,7 +66,7 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.provider.getReviewItemSetFactory());
itemSetConsumer.addObserver(itemSetObserver);
itemSetConsumer.retrieve(false);
- itemSetObserver.waitForResponse(1, 0);
+ itemSetObserver.waitForResponse(false);
PatchSetDetail detail = itemSetConsumer.getRemoteObject();
assertThat(detail.getInfo().getKey().get(), is(3));
@@ -79,7 +79,7 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
testPatchSet, "3");
patchSetConsumer.addObserver(patchSetListener);
patchSetConsumer.retrieve(false);
- patchSetListener.waitForResponse(1, 1);
+ patchSetListener.waitForResponse();
assertThat(fileItems.size(), is(6));
for (IReviewItem fileItem : fileItems) {
@@ -123,14 +123,14 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.addFile("testComments.txt", "line1\nline2\nline3\nline4\nline5\nline6\nline7\n");
reviewHarness.commitAndPush(command2);
reviewHarness.consumer.retrieve(false);
- reviewHarness.listener.waitForResponse(2, 2);
+ 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(1, 0);
+ itemSetObserver.waitForResponse(false);
PatchSetDetail detail = itemSetConsumer.getRemoteObject();
assertThat(detail.getInfo().getKey().get(), is(2));
@@ -142,7 +142,7 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
testPatchSet, "2");
patchSetConsumer.addObserver(patchSetListener);
patchSetConsumer.retrieve(false);
- patchSetListener.waitForResponse(1, 1);
+ patchSetListener.waitForResponse();
IFileItem commentFile = testPatchSet.getItems().get(1);
assertThat(commentFile.getName(), is("testComments.txt"));
@@ -152,7 +152,7 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.client.saveDraft(Patch.Key.parse(id), "Line 2 Comment", 2, (short) 1, null,
new NullProgressMonitor());
patchSetConsumer.retrieve(false);
- patchSetListener.waitForResponse(2, 2);
+ patchSetListener.waitForResponse();
commentFile = testPatchSet.getItems().get(1);
List<IComment> allComments = commentFile.getAllComments();
@@ -166,7 +166,7 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
reviewHarness.client.publishComments(reviewHarness.shortId, 2, "Submit Comments",
Collections.<ApprovalCategoryValue.Id> emptySet(), new NullProgressMonitor());
patchSetConsumer.retrieve(false);
- patchSetListener.waitForResponse(3, 3);
+ patchSetListener.waitForResponse();
allComments = commentFile.getAllComments();
assertThat(allComments.size(), is(1));
fileComment = allComments.get(0);
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/ReviewHarness.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/ReviewHarness.java
index 07645bd..607f4bd 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/ReviewHarness.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/ReviewHarness.java
@@ -88,7 +88,7 @@ class ReviewHarness {
consumer = provider.getReviewFactory().getConsumerForRemoteKey(getRepository(), shortId);
consumer.addObserver(listener);
consumer.retrieve(false);
- listener.waitForResponse(1, 1);
+ listener.waitForResponse();
assertThat(getRepository().getReviews().size(), is(1));
IReview review = getRepository().getReviews().get(0);
IReview reviewDirect = provider.open(shortId);
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 ba17019..cb7f249 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
@@ -47,30 +47,43 @@ final class TestRemoteObserver<P extends EObject, T, L, C> extends RemoteEmfObse
}
}
- protected void waitForResponse(int response, int update) {
- long delay;
- delay = 0;
- while (delay < TEST_TIMEOUT) {
- if (responded < response || updated < update) {
- try {
- Thread.sleep(10);
- delay += 10;
- } catch (InterruptedException e) {
+ public void waitForResponse() {
+ waitForResponse(1, 1);
+ }
+
+ public void waitForResponse(boolean updated) {
+ waitForResponse(1, updated ? 1 : 0);
+ }
+
+ private void waitForResponse(int responses, int updates) {
+ try {
+ long delay;
+ delay = 0;
+ while (delay < TEST_TIMEOUT) {
+ if (responded < responses || updated < updates) {
+ try {
+ Thread.sleep(10);
+ delay += 10;
+ } catch (InterruptedException e) {
+ }
+ } else {
+ break;
}
- } else {
- break;
}
- }
- try {
- //wait extra to ensure there aren't remaining jobs
- Thread.sleep(25);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- assertThat("Wrong # responses: " + responded + ", updated: " + updated, responded, is(response));
- assertThat("Wrong # updates" + updated, updated, is(update));
- if (factory != null) {
- assertThat(factory.getService().isActive(), is(false));
+ try {
+ //wait extra to ensure there aren't remaining jobs
+ Thread.sleep(25);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ assertThat("Wrong # responses: " + responded + ", updated: " + updated, responded, is(responses));
+ assertThat("Wrong # updates" + updated, updated, is(updates));
+ if (factory != null) {
+ assertThat(factory.getService().isActive(), is(false));
+ }
+ } finally {
+ responded = 0;
+ updated = 0;
}
}
} \ No newline at end of file