You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2022/11/04 20:42:03 UTC

[cloudstack] branch main updated: Introducing Hamcrest API to simplify assertion in ImplicitPlannerTest (#6676)

This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 1ee58ec3477 Introducing Hamcrest API to simplify assertion in ImplicitPlannerTest (#6676)
1ee58ec3477 is described below

commit 1ee58ec3477c9f277b1151803c4e8df502d381a2
Author: Codegass <wc...@gmail.com>
AuthorDate: Fri Nov 4 16:41:54 2022 -0400

    Introducing Hamcrest API to simplify assertion in ImplicitPlannerTest (#6676)
    
    Co-authored-by: Daniel Augusto Veronezi Salvador <38...@users.noreply.github.com>
---
 .../implicitplanner/ImplicitPlannerTest.java       | 34 ++++------------------
 1 file changed, 6 insertions(+), 28 deletions(-)

diff --git a/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java b/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
index 529e19940c9..f1645611272 100644
--- a/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
+++ b/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
@@ -18,7 +18,9 @@ package org.apache.cloudstack.implicitplanner;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.equalTo;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -211,15 +213,7 @@ public class ImplicitPlannerTest {
         // 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)));
 
         Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
         assertFalse("Host 5 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(5L));
@@ -248,15 +242,7 @@ public class ImplicitPlannerTest {
         // 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)));
 
         Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
         assertFalse("Host 6 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(6L));
@@ -307,15 +293,7 @@ public class ImplicitPlannerTest {
         // 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)));
 
         Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
         assertFalse("Host 7 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(7L));