From: Robert Varga Date: Fri, 25 Mar 2022 18:27:18 +0000 (+0100) Subject: Migrate yang-common to JUnit5 X-Git-Tag: v8.0.3~21 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=c3a7ca0aa9faa21943fe472f49e94c43943ab90d Migrate yang-common to JUnit5 This is a rather simple conversion with a slight improvement in assertions. Change-Id: I1a17cc0f1f2ffed0e1fb0bbc430f17000546e05d Signed-off-by: Robert Varga --- diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/BiMapYangNamespaceContextTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/BiMapYangNamespaceContextTest.java index 28b56436d5..9113c8a183 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/BiMapYangNamespaceContextTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/BiMapYangNamespaceContextTest.java @@ -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")); diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Decimal64Test.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Decimal64Test.java index 8735a930da..c0440f0de8 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Decimal64Test.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Decimal64Test.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/DerivedStringTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/DerivedStringTest.java index 433f19ffda..fe567440a2 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/DerivedStringTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/DerivedStringTest.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/EmptyTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/EmptyTest.java index a32d54b1ad..7c1f9a3e9e 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/EmptyTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/EmptyTest.java @@ -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 { diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/ErrorTagTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/ErrorTagTest.java index 96dddbaa86..a769e8f0ad 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/ErrorTagTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/ErrorTagTest.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/OperationFailedExceptionTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/OperationFailedExceptionTest.java index e47e53ec85..1e277b4912 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/OperationFailedExceptionTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/OperationFailedExceptionTest.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/QNameTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/QNameTest.java index 90a8e45f39..7ec6496cd4 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/QNameTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/QNameTest.java @@ -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"; diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RevisionTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RevisionTest.java index 47c81cd7f5..e2eb54edfc 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RevisionTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RevisionTest.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RpcResultBuilderTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RpcResultBuilderTest.java index c4a057db4d..5795bc7b1c 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RpcResultBuilderTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/RpcResultBuilderTest.java @@ -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 result = RpcResultBuilder.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 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()); } } diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java index fc9f7a59fc..420276f22d 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint16Test.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java index 1eb936886c..0dc1dd5787 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint32Test.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java index cc79d621c0..5ba683c22f 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint64Test.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java index 2e316d1a03..547f2d91d4 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/Uint8Test.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangConstantsTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangConstantsTest.java index c637b52006..d4c833c46b 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangConstantsTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangConstantsTest.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangNamesTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangNamesTest.java index 58edb3f0bc..a349035a9b 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangNamesTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangNamesTest.java @@ -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 diff --git a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangVersionTest.java b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangVersionTest.java index f2c7b9f1f9..954516cca8 100644 --- a/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangVersionTest.java +++ b/common/yang-common/src/test/java/org/opendaylight/yangtools/yang/common/YangVersionTest.java @@ -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