Cleanup asserts a bit 27/99127/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 21 Dec 2021 08:38:43 +0000 (09:38 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 21 Dec 2021 08:38:43 +0000 (09:38 +0100)
Rather than using String operations, use assertThat() and matchers.

Change-Id: I0e76854950965fbfef739c38b061ccda1a9f1e37
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java

index 7ac18e61dc146a6b27430c884864c39ffe8620d5..3c26d27be0041683d926afbb7f8dd8cef057902b 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -239,8 +242,7 @@ public class ShardTest extends AbstractShardTest {
             CreateTransactionReply.class);
 
         final String path = reply.getTransactionPath().toString();
             CreateTransactionReply.class);
 
         final String path = reply.getTransactionPath().toString();
-        assertTrue("Unexpected transaction path " + path, path.contains(String.format(
-            "/user/testCreateTransaction/shard-%s-%s:ShardTransactionTest@0:",
+        assertThat(path, containsString(String.format("/user/testCreateTransaction/shard-%s-%s:ShardTransactionTest@0:",
             shardID.getShardName(), shardID.getMemberName().getName())));
     }
 
             shardID.getShardName(), shardID.getMemberName().getName())));
     }
 
@@ -258,7 +260,7 @@ public class ShardTest extends AbstractShardTest {
             CreateTransactionReply.class);
 
         final String path = reply.getTransactionPath().toString();
             CreateTransactionReply.class);
 
         final String path = reply.getTransactionPath().toString();
-        assertTrue("Unexpected transaction path " + path, path.contains(String.format(
+        assertThat(path, containsString(String.format(
             "/user/testCreateTransactionOnChain/shard-%s-%s:ShardTransactionTest@0:",
             shardID.getShardName(), shardID.getMemberName().getName())));
     }
             "/user/testCreateTransactionOnChain/shard-%s-%s:ShardTransactionTest@0:",
             shardID.getShardName(), shardID.getMemberName().getName())));
     }
@@ -480,7 +482,7 @@ public class ShardTest extends AbstractShardTest {
                 .fromSerializable(testKit.expectMsgClass(duration, ReadyTransactionReply.class));
 
         String pathSuffix = shard.path().toString().replaceFirst("akka://test", "");
                 .fromSerializable(testKit.expectMsgClass(duration, ReadyTransactionReply.class));
 
         String pathSuffix = shard.path().toString().replaceFirst("akka://test", "");
-        assertTrue("Cohort path", readyReply.getCohortPath().endsWith(pathSuffix));
+        assertThat(readyReply.getCohortPath(), endsWith(pathSuffix));
         // Send the CanCommitTransaction message for the first Tx.
 
         shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), testKit.getRef());
         // Send the CanCommitTransaction message for the first Tx.
 
         shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), testKit.getRef());