Skip to content

Commit 1ee58ec

Browse files
Introducing Hamcrest API to simplify assertion in ImplicitPlannerTest (#6676)
Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com>
1 parent fa39e61 commit 1ee58ec

File tree

1 file changed

+6
-28
lines changed
  • plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner

1 file changed

+6
-28
lines changed

plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import static org.junit.Assert.assertFalse;
2020
import static org.junit.Assert.assertTrue;
21-
import static org.junit.Assert.fail;
21+
import static org.hamcrest.MatcherAssert.assertThat;
22+
import static org.hamcrest.Matchers.everyItem;
23+
import static org.hamcrest.Matchers.equalTo;
2224
import static org.mockito.Matchers.anyString;
2325
import static org.mockito.Mockito.mock;
2426
import static org.mockito.Mockito.when;
@@ -211,15 +213,7 @@ public void checkStrictModeWithCurrentAccountVmsPresent() throws InsufficientSer
211213
// Check cluster 2 and 3 are not in the cluster list.
212214
// Host 6 and 7 should also be in avoid list.
213215
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
214-
boolean foundNeededCluster = false;
215-
for (Long cluster : clusterList) {
216-
if (cluster != 1) {
217-
fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
218-
} else {
219-
foundNeededCluster = true;
220-
}
221-
}
222-
assertTrue("Didn't find cluster 1 in the list. It should have been present", foundNeededCluster);
216+
assertThat("Found cluster that shouldn't have been present, only cluster 1 should be present", clusterList, everyItem(equalTo(1L)));
223217

224218
Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
225219
assertFalse("Host 5 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(5L));
@@ -248,15 +242,7 @@ public void checkStrictModeHostWithCurrentAccountVmsFull() throws InsufficientSe
248242
// Check cluster 1 and 3 are not in the cluster list.
249243
// Host 5 and 7 should also be in avoid list.
250244
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
251-
boolean foundNeededCluster = false;
252-
for (Long cluster : clusterList) {
253-
if (cluster != 2) {
254-
fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
255-
} else {
256-
foundNeededCluster = true;
257-
}
258-
}
259-
assertTrue("Didn't find cluster 2 in the list. It should have been present", foundNeededCluster);
245+
assertThat("Found cluster that shouldn't have been present, only cluster 2 should be present", clusterList, everyItem(equalTo(2L)));
260246

261247
Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
262248
assertFalse("Host 6 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(6L));
@@ -307,15 +293,7 @@ public void checkPreferredModePreferredHostAvailable() throws InsufficientServer
307293
// Check cluster 1 and 2 are not in the cluster list.
308294
// Host 5 and 6 should also be in avoid list.
309295
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
310-
boolean foundNeededCluster = false;
311-
for (Long cluster : clusterList) {
312-
if (cluster != 3) {
313-
fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
314-
} else {
315-
foundNeededCluster = true;
316-
}
317-
}
318-
assertTrue("Didn't find cluster 3 in the list. It should have been present", foundNeededCluster);
296+
assertThat("Found cluster that shouldn't have been present, only cluster 3 should be present", clusterList, everyItem(equalTo(3L)));
319297

320298
Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
321299
assertFalse("Host 7 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(7L));

0 commit comments

Comments
 (0)