Deflake DownstreamCreatorIT by sorting by branch instead of number.

Change-Id: I77723a8794a15964ffdc99b9f54b0da84b962842
diff --git a/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java b/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
index ab90ba8..f79d3d5 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
@@ -70,23 +70,23 @@
     merge(result);
     List<ChangeInfo> sortedChanges = sortedChanges(changesInTopic);
 
-    ChangeInfo masterChangeInfo = sortedChanges.get(0);
-    ChangeApi masterChange = gApi.changes().id(masterChangeInfo._number);
-    assertThat(getVote(masterChange, "Code-Review").value).isEqualTo(2);
-    assertThat(getVote(masterChange, "Code-Review").tag).isEqualTo(null);
-    assertThat(masterChangeInfo.branch).isEqualTo("master");
-
-    ChangeInfo dsOneChangeInfo = sortedChanges.get(1);
+    ChangeInfo dsOneChangeInfo = sortedChanges.get(0);
     assertThat(dsOneChangeInfo.branch).isEqualTo("ds_one");
     ChangeApi dsOneChange = gApi.changes().id(dsOneChangeInfo._number);
     assertThat(getVote(dsOneChange, "Code-Review").value).isEqualTo(2);
     assertThat(getVote(dsOneChange, "Code-Review").tag).isEqualTo("autogenerated:Automerger");
 
-    ChangeInfo dsTwoChangeInfo = sortedChanges.get(2);
+    ChangeInfo dsTwoChangeInfo = sortedChanges.get(1);
     assertThat(dsTwoChangeInfo.branch).isEqualTo("ds_two");
     ChangeApi dsTwoChange = gApi.changes().id(dsTwoChangeInfo._number);
     assertThat(getVote(dsTwoChange, "Code-Review").value).isEqualTo(2);
     assertThat(getVote(dsTwoChange, "Code-Review").tag).isEqualTo("autogenerated:Automerger");
+
+    ChangeInfo masterChangeInfo = sortedChanges.get(2);
+    ChangeApi masterChange = gApi.changes().id(masterChangeInfo._number);
+    assertThat(getVote(masterChange, "Code-Review").value).isEqualTo(2);
+    assertThat(getVote(masterChange, "Code-Review").tag).isEqualTo(null);
+    assertThat(masterChangeInfo.branch).isEqualTo("master");
   }
 
   @Test
@@ -112,13 +112,7 @@
 
     List<ChangeInfo> sortedChanges = sortedChanges(changesInTopic);
 
-    ChangeInfo masterChangeInfo = sortedChanges.get(0);
-    ChangeApi masterChange = gApi.changes().id(masterChangeInfo._number);
-    assertThat(getVote(masterChange, "Code-Review").value).isEqualTo(0);
-    assertThat(getVote(masterChange, "Code-Review").tag).isEqualTo(null);
-    assertThat(masterChangeInfo.branch).isEqualTo("master");
-
-    ChangeInfo dsOneChangeInfo = sortedChanges.get(1);
+    ChangeInfo dsOneChangeInfo = sortedChanges.get(0);
     assertThat(dsOneChangeInfo.branch).isEqualTo("ds_one");
     ChangeApi dsOneChange = gApi.changes().id(dsOneChangeInfo._number);
     assertThat(getVote(dsOneChange, "Code-Review").value).isEqualTo(0);
@@ -128,7 +122,7 @@
     assertThat(dsOneChange.current().files().keySet()).contains("filename");
     assertThat(dsOneChange.current().files().get("filename").linesDeleted).isEqualTo(1);
 
-    ChangeInfo dsTwoChangeInfo = sortedChanges.get(2);
+    ChangeInfo dsTwoChangeInfo = sortedChanges.get(1);
     assertThat(dsTwoChangeInfo.branch).isEqualTo("ds_two");
     ChangeApi dsTwoChange = gApi.changes().id(dsTwoChangeInfo._number);
     assertThat(getVote(dsTwoChange, "Code-Review").value).isEqualTo(0);
@@ -137,6 +131,12 @@
     assertThat(dsTwoChange.get().subject).doesNotContain("skipped:");
     BinaryResult dsTwoContent = dsTwoChange.current().file("filename").content();
     assertThat(dsTwoContent.asString()).isEqualTo(content.asString());
+
+    ChangeInfo masterChangeInfo = sortedChanges.get(2);
+    ChangeApi masterChange = gApi.changes().id(masterChangeInfo._number);
+    assertThat(getVote(masterChange, "Code-Review").value).isEqualTo(0);
+    assertThat(getVote(masterChange, "Code-Review").tag).isEqualTo(null);
+    assertThat(masterChangeInfo.branch).isEqualTo("master");
   }
 
   @Test
@@ -160,13 +160,7 @@
 
     List<ChangeInfo> sortedChanges = sortedChanges(changesInTopic);
 
-    ChangeInfo masterChangeInfo = sortedChanges.get(0);
-    ChangeApi masterChange = gApi.changes().id(masterChangeInfo._number);
-    assertThat(getVote(masterChange, "Code-Review").value).isEqualTo(0);
-    assertThat(getVote(masterChange, "Code-Review").tag).isEqualTo(null);
-    assertThat(masterChangeInfo.branch).isEqualTo("master");
-
-    ChangeInfo dsOneChangeInfo = sortedChanges.get(1);
+    ChangeInfo dsOneChangeInfo = sortedChanges.get(0);
     assertThat(dsOneChangeInfo.branch).isEqualTo("ds_one");
     ChangeApi dsOneChange = gApi.changes().id(dsOneChangeInfo._number);
     assertThat(getVote(dsOneChange, "Code-Review").value).isEqualTo(0);
@@ -176,7 +170,7 @@
     assertThat(dsOneChange.current().files().keySet()).contains("filename");
     assertThat(dsOneChange.current().files().get("filename").linesDeleted).isEqualTo(1);
 
-    ChangeInfo dsTwoChangeInfo = sortedChanges.get(2);
+    ChangeInfo dsTwoChangeInfo = sortedChanges.get(1);
     assertThat(dsTwoChangeInfo.branch).isEqualTo("ds_two");
     ChangeApi dsTwoChange = gApi.changes().id(dsTwoChangeInfo._number);
     assertThat(getVote(dsTwoChange, "Code-Review").value).isEqualTo(0);
@@ -185,6 +179,12 @@
     assertThat(dsTwoChange.get().subject).contains("skipped:");
     assertThat(dsTwoChange.current().files().keySet()).contains("filename");
     assertThat(dsTwoChange.current().files().get("filename").linesDeleted).isEqualTo(1);
+
+    ChangeInfo masterChangeInfo = sortedChanges.get(2);
+    ChangeApi masterChange = gApi.changes().id(masterChangeInfo._number);
+    assertThat(getVote(masterChange, "Code-Review").value).isEqualTo(0);
+    assertThat(getVote(masterChange, "Code-Review").tag).isEqualTo(null);
+    assertThat(masterChangeInfo.branch).isEqualTo("master");
   }
 
   @Test
@@ -226,18 +226,18 @@
     assertThat(changesInTopic).hasSize(2);
     List<ChangeInfo> sortedChanges = sortedChanges(changesInTopic);
 
-    ChangeInfo masterChangeInfo = sortedChanges.get(0);
-    ChangeApi masterChange = gApi.changes().id(masterChangeInfo._number);
-    assertThat(getVote(masterChange, "Code-Review").value).isEqualTo(-2);
-    assertThat(getVote(masterChange, "Code-Review").tag).isEqualTo("autogenerated:MergeConflict");
-    assertThat(masterChangeInfo.branch).isEqualTo("master");
-
-    ChangeInfo dsTwoChangeInfo = sortedChanges.get(1);
+    ChangeInfo dsTwoChangeInfo = sortedChanges.get(0);
     assertThat(dsTwoChangeInfo.branch).isEqualTo("ds_two");
     ChangeApi dsTwoChange = gApi.changes().id(dsTwoChangeInfo._number);
     // This is -2 because the -2 vote from master propagated to ds_two
     assertThat(getVote(dsTwoChange, "Code-Review").value).isEqualTo(-2);
     assertThat(getVote(dsTwoChange, "Code-Review").tag).isEqualTo("autogenerated:Automerger");
+
+    ChangeInfo masterChangeInfo = sortedChanges.get(1);
+    ChangeApi masterChange = gApi.changes().id(masterChangeInfo._number);
+    assertThat(getVote(masterChange, "Code-Review").value).isEqualTo(-2);
+    assertThat(getVote(masterChange, "Code-Review").tag).isEqualTo("autogenerated:MergeConflict");
+    assertThat(masterChangeInfo.branch).isEqualTo("master");
   }
 
   @Test
@@ -400,7 +400,7 @@
         new Comparator<ChangeInfo>() {
           @Override
           public int compare(ChangeInfo c1, ChangeInfo c2) {
-            return c1._number - c2._number;
+            return c1.branch.compareTo(c2.branch);
           }
         });
     return listCopy;