svn: Refactored "SvnQuickMergeTest" - removed duplication
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Mon, 26 Sep 2016 19:02:20 +0000 (22:02 +0300)
committerKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Tue, 11 Oct 2016 01:28:23 +0000 (04:28 +0300)
Reused common "wait for quick merge completion" logic

plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnQuickMergeTest.java

index 477b6f51461bc7c5d57bbdb665488e6dd09d4670..2fb380cdf2a5851fffa21417275a0548ad87cde8 100644 (file)
@@ -108,20 +108,7 @@ public class SvnQuickMergeTest extends Svn17TestCase {
     VcsTestUtil.editFileInCommand(myProject, myBranchTree.myS1File, "edited in branch");
     runInAndVerifyIgnoreOutput(myBranchRoot, "ci", "-m", "change in branch", myBranchTree.myS1File.getPath());
 
-    final QuickMerge quickMerge = newQuickMerge(myBranchUrl);
-    // by default merges all
-    QuickMergeTestInteraction testInteraction = new QuickMergeTestInteraction(true);
-    final WaitingTaskDescriptor descriptor = new WaitingTaskDescriptor();
-    ApplicationManager.getApplication().invokeLater(new Runnable() {
-      @Override
-      public void run() {
-        quickMerge.execute(testInteraction, descriptor);
-      }
-    });
-    descriptor.waitForCompletion();
-    testInteraction.throwIfExceptions();
-
-    Assert.assertTrue(descriptor.isCompleted());
+    waitQuickMerge(myBranchUrl, new QuickMergeTestInteraction(true));
 
     VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
     myChangeListManager.ensureUpToDate(false);
@@ -168,9 +155,7 @@ public class SvnQuickMergeTest extends Svn17TestCase {
     }
 
     // we should get exactly 2 revisions for selection (copy and change in b2)
-    final QuickMerge quickMerge = newQuickMerge(myBranchUrl);
-    // by default merges all
-    final AtomicReference<String> selectionError = new AtomicReference<>();
+    AtomicReference<String> selectionError = new AtomicReference<>();
     QuickMergeTestInteraction testInteraction = new QuickMergeTestInteraction(true) {
       @NotNull
       @Override
@@ -186,21 +171,13 @@ public class SvnQuickMergeTest extends Svn17TestCase {
       }
     };
     testInteraction.setMergeVariant(QuickMergeContentsVariants.showLatest);
-    final WaitingTaskDescriptor descriptor = new WaitingTaskDescriptor();
-    ApplicationManager.getApplication().invokeLater(new Runnable() {
-      @Override
-      public void run() {
-        quickMerge.execute(testInteraction, descriptor);
-      }
-    });
-    descriptor.waitForCompletion();
-    testInteraction.throwIfExceptions();
+
+    waitQuickMerge(myBranchUrl, testInteraction);
+
     if (selectionError.get() != null){
       throw new RuntimeException(selectionError.get());
     }
 
-    Assert.assertTrue(descriptor.isCompleted());
-
     VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
     myChangeListManager.ensureUpToDate(false);
 
@@ -254,9 +231,7 @@ public class SvnQuickMergeTest extends Svn17TestCase {
     runInAndVerifyIgnoreOutput(myBranchRoot, "ci", "-m", "change in b2", myBranchTree.myS2File.getPath());
 
     // we should get exactly 2 revisions for selection (copy and change in b2)
-    final QuickMerge quickMerge = newQuickMerge(myRepoUrl + "/branches/b2");
-    // by default merges all
-    final AtomicReference<String> selectionError = new AtomicReference<>();
+    AtomicReference<String> selectionError = new AtomicReference<>();
     QuickMergeTestInteraction testInteraction = new QuickMergeTestInteraction(true) {
       @NotNull
       @Override
@@ -272,21 +247,13 @@ public class SvnQuickMergeTest extends Svn17TestCase {
       }
     };
     testInteraction.setMergeVariant(QuickMergeContentsVariants.showLatest);
-    final WaitingTaskDescriptor descriptor = new WaitingTaskDescriptor();
-    ApplicationManager.getApplication().invokeLater(new Runnable() {
-      @Override
-      public void run() {
-        quickMerge.execute(testInteraction, descriptor);
-      }
-    });
-    descriptor.waitForCompletion();
-    testInteraction.throwIfExceptions();
+
+    waitQuickMerge(myRepoUrl + "/branches/b2", testInteraction);
+
     if (selectionError.get() != null){
       throw new RuntimeException(selectionError.get());
     }
 
-    Assert.assertTrue(descriptor.isCompleted());
-
     VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
     myChangeListManager.ensureUpToDate(false);
 
@@ -322,8 +289,6 @@ public class SvnQuickMergeTest extends Svn17TestCase {
       Thread.sleep(10);
     }
 
-    final QuickMerge quickMerge = newQuickMerge(myBranchUrl);
-    // by default merges all
     QuickMergeTestInteraction testInteraction = new QuickMergeTestInteraction(true) {
       @NotNull
       @Override
@@ -348,17 +313,8 @@ public class SvnQuickMergeTest extends Svn17TestCase {
       }
     };
     testInteraction.setMergeVariant(QuickMergeContentsVariants.select);
-    final WaitingTaskDescriptor descriptor = new WaitingTaskDescriptor();
-    ApplicationManager.getApplication().invokeLater(new Runnable() {
-      @Override
-      public void run() {
-        quickMerge.execute(testInteraction, descriptor);
-      }
-    });
-    descriptor.waitForCompletion();
-    testInteraction.throwIfExceptions();
 
-    Assert.assertTrue(descriptor.isCompleted());
+    waitQuickMerge(myBranchUrl, testInteraction);
 
     VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
     myChangeListManager.ensureUpToDate(false);
@@ -405,20 +361,8 @@ public class SvnQuickMergeTest extends Svn17TestCase {
     myTree = new SubTree(myWorkingCopyDir); //reload
 
     refreshSvnMappingsSynchronously();
-    final QuickMerge quickMerge = newQuickMerge(trunkUrl);
-    // by default merges all
-    QuickMergeTestInteraction testInteraction = new QuickMergeTestInteraction(false);
-    final WaitingTaskDescriptor descriptor = new WaitingTaskDescriptor();
-    ApplicationManager.getApplication().invokeLater(new Runnable() {
-      @Override
-      public void run() {
-        quickMerge.execute(testInteraction, descriptor);
-      }
-    });
-    descriptor.waitForCompletion();
-    testInteraction.throwIfExceptions();
 
-    Assert.assertTrue(descriptor.isCompleted());
+    waitQuickMerge(trunkUrl, new QuickMergeTestInteraction(false));
 
     VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
     myChangeListManager.ensureUpToDate(false);
@@ -433,10 +377,17 @@ public class SvnQuickMergeTest extends Svn17TestCase {
     Assert.assertEquals(FileStatus.MODIFIED, dirChange.getFileStatus());
   }
 
-  private QuickMerge newQuickMerge(@NotNull String sourceUrl) {
+  private void waitQuickMerge(@NotNull String sourceUrl, @NotNull QuickMergeTestInteraction interaction) throws Exception {
     MergeContext mergeContext = new MergeContext(myVcs, sourceUrl, getWcInfo(), SVNPathUtil.tail(sourceUrl), myWorkingCopyDir);
+    QuickMerge quickMerge = new QuickMerge(mergeContext);
+    WaitingTaskDescriptor descriptor = new WaitingTaskDescriptor();
+
+    ApplicationManager.getApplication().invokeLater(() -> quickMerge.execute(interaction, descriptor));
 
-    return new QuickMerge(mergeContext);
+    descriptor.waitForCompletion();
+    interaction.throwIfExceptions();
+
+    Assert.assertTrue(descriptor.isCompleted());
   }
 
   private static class WaitingTaskDescriptor extends TaskDescriptor {