You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/09/09 14:20:43 UTC

[GitHub] [cloudstack] GutoVeronezi commented on a diff in pull request #6676: Introducing Hamcrest API to simplify assertion in ImplicitPlannerTest

GutoVeronezi commented on code in PR #6676:
URL: https://github.com/apache/cloudstack/pull/6676#discussion_r967125081


##########
plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java:
##########
@@ -248,15 +242,7 @@ public void checkStrictModeHostWithCurrentAccountVmsFull() throws InsufficientSe
         // Check cluster 1 and 3 are not in the cluster list.
         // Host 5 and 7 should also be in avoid list.
         assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
-        boolean foundNeededCluster = false;
-        for (Long cluster : clusterList) {
-            if (cluster != 2) {
-                fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
-            } else {
-                foundNeededCluster = true;
-            }
-        }
-        assertTrue("Didn't find cluster 2 in the list. It should have been present", foundNeededCluster);
+        assertThat("Found cluster that shouldn't have been present, only cluster 2 should be present",clusterList, everyItem(equalTo(2L)));

Review Comment:
   ```suggestion
           assertThat("Found cluster that shouldn't have been present, only cluster 2 should be present", clusterList, everyItem(equalTo(2L)));
   ```



##########
plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java:
##########
@@ -307,15 +293,7 @@ public void checkPreferredModePreferredHostAvailable() throws InsufficientServer
         // Check cluster 1 and 2 are not in the cluster list.
         // Host 5 and 6 should also be in avoid list.
         assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
-        boolean foundNeededCluster = false;
-        for (Long cluster : clusterList) {
-            if (cluster != 3) {
-                fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
-            } else {
-                foundNeededCluster = true;
-            }
-        }
-        assertTrue("Didn't find cluster 3 in the list. It should have been present", foundNeededCluster);
+        assertThat("Found cluster that shouldn't have been present, only cluster 3 should be present",clusterList, everyItem(equalTo(3L)));

Review Comment:
   ```suggestion
           assertThat("Found cluster that shouldn't have been present, only cluster 3 should be present", clusterList, everyItem(equalTo(3L)));
   ```



##########
plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java:
##########
@@ -211,15 +213,7 @@ public void checkStrictModeWithCurrentAccountVmsPresent() throws InsufficientSer
         // Check cluster 2 and 3 are not in the cluster list.
         // Host 6 and 7 should also be in avoid list.
         assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
-        boolean foundNeededCluster = false;
-        for (Long cluster : clusterList) {
-            if (cluster != 1) {
-                fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
-            } else {
-                foundNeededCluster = true;
-            }
-        }
-        assertTrue("Didn't find cluster 1 in the list. It should have been present", foundNeededCluster);
+        assertThat("Found cluster that shouldn't have been present, only cluster 1 should be present",clusterList, everyItem(equalTo(1L)));

Review Comment:
   ```suggestion
           assertThat("Found cluster that shouldn't have been present, only cluster 1 should be present", clusterList, everyItem(equalTo(1L)));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org