Modernize AbstractLocalTransactionRequestTest 97/103097/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 4 Nov 2022 21:17:46 +0000 (22:17 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 4 Nov 2022 21:18:31 +0000 (22:18 +0100)
Use static imports and use assertThrows() and better assertion on the
thrown exception.

Change-Id: I9b11e8a6797b76efa52f1eb3506b630de4a3ae44
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalTransactionRequestTest.java

index e40a39450b78c7b5462cae45b2cf9407c369a9cc..49755f7522109521f63556c8bc1bc20b50c85552 100644 (file)
@@ -7,8 +7,14 @@
  */
 package org.opendaylight.controller.cluster.access.commands;
 
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+
 import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 
@@ -19,12 +25,15 @@ public abstract class AbstractLocalTransactionRequestTest<T extends AbstractLoca
 
     @Test
     public void cloneAsVersionTest() {
-        Assert.assertEquals(object(), object().cloneAsVersion(ABIVersion.BORON));
+        assertSame(object(), object().cloneAsVersion(ABIVersion.BORON));
     }
 
     @Override
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void serializationTest() {
-        SerializationUtils.clone(object());
+        final var ex = assertThrows(UnsupportedOperationException.class, () -> SerializationUtils.clone(object()));
+        assertThat(ex.getMessage(), allOf(
+            startsWith("Local transaction request "),
+            endsWith(" should never be serialized")));
     }
 }