Migrate yang-common to JUnit5 67/100267/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 25 Mar 2022 18:27:18 +0000 (19:27 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 25 Mar 2022 18:27:18 +0000 (19:27 +0100)
This is a rather simple conversion with a slight improvement in
assertions.

Change-Id: I1a17cc0f1f2ffed0e1fb0bbc430f17000546e05d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
16 files changed:
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/BiMapYangNamespaceContextTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Decimal64Test.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/DerivedStringTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/EmptyTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/ErrorTagTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/OperationFailedExceptionTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/QNameTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RevisionTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RpcResultBuilderTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangConstantsTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangNamesTest.java
common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangVersionTest.java

index 28b56436d521a7b6958bbabfd31118c316ea279f..9113c8a183192be6da0638381a15593b9ed19a7a 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import com.google.common.collect.ImmutableBiMap;
 import java.io.ByteArrayInputStream;
@@ -18,7 +18,7 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class BiMapYangNamespaceContextTest {
     private static final QNameModule FOO = QNameModule.create(XMLNamespace.of("foo"));
index 8735a930da92b114c03831cee1783831b44f6057..c0440f0de880fcdfac611521af9267755f14f937 100644 (file)
@@ -7,14 +7,15 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class Decimal64Test {
     @Test
index 433f19ffda265a60dc9c518858fa5930d198f159..fe567440a22066a650bb71b604447aab6d0226ea 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.concepts.Either;
 
 @NonNullByDefault
index a32d54b1ad67c7dfc375828558b77d863750c7bb..7c1f9a3e9ea14b234d98c288b292123f2579f971 100644 (file)
@@ -7,16 +7,16 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class EmptyTest {
 
index 96dddbaa8684435e5bfcb43bea26d63bfbd52a86..a769e8f0ad60eb062115d2e6a613cd9b52bbd597 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class ErrorTagTest {
     @Test
index e47e53ec855e92bbc356f99b5f14fb327fa73324..1e277b49128098ce32b09c6ccb0334eb5610f956 100644 (file)
@@ -9,9 +9,9 @@ package org.opendaylight.yangtools.yang.common;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class OperationFailedExceptionTest {
     @Test
index 90a8e45f39082e5cde0006a4b1c82eb2ffc27bf7..7ec6496cd4ec0a15bf14e53c5bc000da5dcad8bf 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.net.URISyntaxException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class QNameTest {
     private static final String NAMESPACE = "urn:foo";
index 47c81cd7f5eb079331f352cba420eeeed6829f1d..e2eb54edfc7da3fe84e80baecf139a48892c85f9 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -19,7 +19,7 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.time.format.DateTimeParseException;
 import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class RevisionTest {
     @Test
index c4a057db4dee93db5b204a74ff2ff3a597ddf596..5795bc7b1cbaa3bf4bcea266e6c7d6fdfd4090e6 100644 (file)
@@ -7,16 +7,17 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 /**
  * Unit tests for RpcResultBuilder.
@@ -30,8 +31,7 @@ public class RpcResultBuilderTest {
     public void testSuccess() {
         RpcResult<String> result = RpcResultBuilder.<String>success().withResult("foo").build();
         verifyRpcResult(result, true, "foo");
-        assertNotNull("getErrors returned null", result.getErrors());
-        assertEquals("getErrors size", 0, result.getErrors().size());
+        assertEquals(List.of(), result.getErrors());
 
         result = RpcResultBuilder.success("bar").build();
         verifyRpcResult(result, true, "bar");
@@ -56,7 +56,7 @@ public class RpcResultBuilderTest {
                         "my-info", cause);
         verifyRpcError(result, 3, ErrorSeverity.ERROR, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED,
                         "error message 4", null, null, cause2);
-        assertEquals("getErrors size", 4, result.getErrors().size());
+        assertEquals(4, result.getErrors().size());
     }
 
     @Test
@@ -71,7 +71,7 @@ public class RpcResultBuilderTest {
                         null, null);
         verifyRpcError(result, 1, ErrorSeverity.WARNING, ErrorType.RPC, ErrorTag.IN_USE, "message 2", "my-app-tag",
                         "my-info", cause);
-        assertEquals("getErrors size", 2, result.getErrors().size());
+        assertEquals(2, result.getErrors().size());
     }
 
     @Test
@@ -164,19 +164,20 @@ public class RpcResultBuilderTest {
             final String expInfo, final Throwable expCause) {
 
         List<RpcError> errors = result.getErrors();
-        assertTrue("Expected error at index " + errorIndex + " not found", errorIndex < errors.size());
+        assertThat(errors.size(), greaterThanOrEqualTo(errorIndex));
+
         RpcError error = errors.get(errorIndex);
-        assertEquals("getSeverity", expSeverity, error.getSeverity());
-        assertEquals("getErrorType", expErrorType, error.getErrorType());
-        assertEquals("getTag", expTag, error.getTag());
-        assertEquals("getMessage", expMessage, error.getMessage());
-        assertEquals("getApplicationTag", expAppTag, error.getApplicationTag());
-        assertEquals("getInfo", expInfo, error.getInfo());
-        assertEquals("getCause", expCause, error.getCause());
+        assertEquals(expSeverity, error.getSeverity());
+        assertEquals(expErrorType, error.getErrorType());
+        assertEquals(expTag, error.getTag());
+        assertEquals(expMessage, error.getMessage());
+        assertEquals(expAppTag, error.getApplicationTag());
+        assertEquals(expInfo, error.getInfo());
+        assertEquals(expCause, error.getCause());
     }
 
     void verifyRpcResult(final RpcResult<?> result, final boolean expSuccess, final Object expValue) {
-        assertEquals("isSuccessful", expSuccess, result.isSuccessful());
-        assertEquals("getResult", expValue, result.getResult());
+        assertEquals(expSuccess, result.isSuccessful());
+        assertEquals(expValue, result.getResult());
     }
 }
index fc9f7a59fc03f1b6858839331cbd232f680be516..420276f22da0d5fa603109d3f0542e6b26b17b02 100644 (file)
@@ -10,18 +10,18 @@ package org.opendaylight.yangtools.yang.common;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.lessThan;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class Uint16Test {
     @Test
index 1eb936886c0f95d17cc91497de241998cf6e4b3d..0dc1dd5787a335a191917f1ee2bb41e67795b706 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import com.google.common.primitives.UnsignedInteger;
 import java.io.ByteArrayInputStream;
@@ -19,7 +19,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class Uint32Test {
     @Test
index cc79d621c02c12c0d8bccee631f580295f902856..5ba683c22ff1195b36784f683de93c0121205c50 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import com.google.common.primitives.UnsignedLong;
 import java.io.ByteArrayInputStream;
@@ -20,7 +20,7 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.math.BigInteger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class Uint64Test {
     @Test
index 2e316d1a0388d95bf577502848f4006e1bc178c7..547f2d91d46c7f1a057a469cdf0679934ee277a0 100644 (file)
@@ -7,18 +7,18 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class Uint8Test {
     @Test
index c637b52006bcd8f43eed72fa0dbbdb2420451736..d4c833c46bc4565ac884e2868ecd74be4ae595c7 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class YangConstantsTest {
     @Test
index 58edb3f0bc3309cd1eb881153ef5796a0674929c..a349035a9b34825bd85ce10cb66dd6361c7f9116 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.util.AbstractMap.SimpleImmutableEntry;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class YangNamesTest {
     @Test
index f2c7b9f1f9fe4bde5712a28336b84c11e892c1de..954516cca8b9065c49266ee6839998d58e6eb17b 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.util.Optional;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class YangVersionTest {
     @Test