From a0c2f1b5e2b757e4ff5a5e7ea19fc64d67fb3f51 Mon Sep 17 00:00:00 2001 From: "matus.matok" Date: Thu, 13 Jul 2023 09:37:27 +0200 Subject: [PATCH] Migrate yang-data-impl to JUnit5 Migrated all tests to use JUnit5 Assertions, using openrewrite:rewrite-testing-frameworks. Manually corrected variable modifiers, including migration to 'var'. JIRA: YANGTOOLS-1521 Change-Id: Iecffb046c782ec732da51d9d92738d3bfebf5ef4 Signed-off-by: matus.matok Signed-off-by: Robert Varga --- .../impl/codec/BinaryCodecStringTest.java | 21 +- .../data/impl/codec/BitsCodecStringTest.java | 38 +- .../impl/codec/BooleanCodecStringTest.java | 22 +- .../impl/codec/DecimalCodecStringTest.java | 14 +- .../data/impl/codec/EmptyCodecStringTest.java | 19 +- .../data/impl/codec/EnumCodecStringTest.java | 20 +- .../data/impl/codec/Int16CodecStringTest.java | 40 +- .../data/impl/codec/Int32CodecStringTest.java | 40 +- .../data/impl/codec/Int64CodecStringTest.java | 45 ++- .../data/impl/codec/Int8CodecStringTest.java | 44 +-- .../impl/codec/StringCodecStringTest.java | 32 +- .../codec/StringPatternCheckingCodecTest.java | 12 +- .../TypeDefinitionAwareCodecTestHelper.java | 26 +- .../impl/codec/Uint16CodecStringTest.java | 20 +- .../impl/codec/Uint32CodecStringTest.java | 20 +- .../impl/codec/Uint64CodecStringTest.java | 20 +- .../data/impl/codec/Uint8CodecStringTest.java | 24 +- .../data/impl/codec/UnionCodecStringTest.java | 37 +- .../yang/data/impl/codec/YT1097Test.java | 28 +- .../yang/data/impl/codec/YT1437Test.java | 29 +- .../yang/data/impl/codec/YT1442Test.java | 47 +-- .../yang/data/impl/schema/BuilderTest.java | 169 +++------ ...mutableNormalizedNodeStreamWriterTest.java | 17 +- .../impl/schema/InstanceIdToNodesTest.java | 43 +-- .../schema/NormalizedDataBuilderTest.java | 73 ++-- .../impl/schema/NormalizedNodeUtilsTest.java | 103 +++--- .../impl/schema/OrderingEqualityTest.java | 45 ++- ...tImmutableNormalizedValueAttrNodeTest.java | 341 +++++++++--------- .../data/impl/schema/nodes/YT1417Test.java | 20 +- 29 files changed, 639 insertions(+), 770 deletions(-) diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BinaryCodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BinaryCodecStringTest.java index b147c9b268..101fa32318 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BinaryCodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BinaryCodecStringTest.java @@ -7,12 +7,11 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Base64; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -21,20 +20,20 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class BinaryCodecStringTest { +class BinaryCodecStringTest { private static final byte[] FOUR_ELEMENTS = { 1, 2, 3, 4 }; - @SuppressWarnings("unchecked") @Test - public void testSerialize() { - BinaryCodec codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class); + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.binaryType(), BinaryCodec.class); assertEquals(Base64.getEncoder().encodeToString(FOUR_ELEMENTS), codec.serialize(FOUR_ELEMENTS)); } - @SuppressWarnings("unchecked") @Test - public void testDererialize() { - BinaryCodec codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class); + void testDererialize() { + @SuppressWarnings("unchecked") + final var codec = (BinaryCodec) + TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.binaryType(), BinaryCodec.class); assertArrayEquals(FOUR_ELEMENTS, codec.deserialize(Base64.getEncoder().encodeToString(FOUR_ELEMENTS))); } } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BitsCodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BitsCodecStringTest.java index 444b21ef3d..f377b3bbae 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BitsCodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BitsCodecStringTest.java @@ -7,34 +7,32 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import com.google.common.collect.ImmutableSet; -import java.util.Collections; -import org.junit.Test; +import java.util.Set; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.data.api.codec.BitsCodec; import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; -import org.opendaylight.yangtools.yang.model.ri.type.BitsTypeBuilder; /** * Unit tests for BitsCodecString. * * @author Thomas Pantelis */ -public class BitsCodecStringTest { +class BitsCodecStringTest { private static BitsTypeDefinition toBitsTypeDefinition(final String... bits) { - final BitsTypeBuilder b = BaseTypes.bitsTypeBuilder(QName.create("foo", "foo")); + final var b = BaseTypes.bitsTypeBuilder(QName.create("foo", "foo")); long pos = 0; - for (String bit : bits) { - BitsTypeDefinition.Bit mockBit = mock(BitsTypeDefinition.Bit.class); + for (var bit : bits) { + final var mockBit = mock(Bit.class); doReturn(bit).when(mockBit).getName(); doReturn(Uint32.valueOf(pos)).when(mockBit).getPosition(); b.addBit(mockBit); @@ -46,26 +44,24 @@ public class BitsCodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - BitsCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(toBitsTypeDefinition("foo"), + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(toBitsTypeDefinition("foo"), BitsCodec.class); - String serialized = codec.serialize(ImmutableSet.of("foo", "bar")); - assertNotNull(serialized); - assertTrue(serialized.contains("foo")); - assertTrue(serialized.contains("bar")); + final var serialized = ((BitsCodec) codec).serialize(ImmutableSet.of("foo", "bar")); + assertEquals("foo bar", serialized); - assertEquals("", codec.serialize(ImmutableSet.of())); + assertEquals("", codec.serialize(Set.of())); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - BitsCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( + void testDeserialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec( toBitsTypeDefinition("bit1", "bit2"), BitsCodec.class); - assertEquals("deserialize", ImmutableSet.of("bit1", "bit2"), codec.deserialize(" bit1 bit2 ")); - assertEquals("deserialize", Collections.emptySet(), codec.deserialize("")); + assertEquals(Set.of("bit1", "bit2"), codec.deserialize(" bit1 bit2 "), "deserialize"); + assertEquals(Set.of(), codec.deserialize(""), "deserialize"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "bit1 bit3"); } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BooleanCodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BooleanCodecStringTest.java index 0223e9e624..8c29bd2670 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BooleanCodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/BooleanCodecStringTest.java @@ -7,9 +7,9 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -18,25 +18,25 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class BooleanCodecStringTest { +class BooleanCodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - BooleanCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(), + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(), BooleanCodec.class); - assertEquals("serialize", "true", codec.serialize(Boolean.TRUE)); - assertEquals("serialize", "false", codec.serialize(Boolean.FALSE)); + assertEquals("true", codec.serialize(Boolean.TRUE), "serialize"); + assertEquals("false", codec.serialize(Boolean.FALSE), "serialize"); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - BooleanCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(), + void testDeserialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(), BooleanCodec.class); - assertEquals("deserialize", Boolean.TRUE, codec.deserialize("true")); - assertEquals("deserialize", Boolean.FALSE, codec.deserialize("false")); + assertEquals(Boolean.TRUE, codec.deserialize("true"), "deserialize"); + assertEquals(Boolean.FALSE, codec.deserialize("false"), "deserialize"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "TRUE"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "FALSE"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo"); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/DecimalCodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/DecimalCodecStringTest.java index 8d564f0171..cf557a3977 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/DecimalCodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/DecimalCodecStringTest.java @@ -7,9 +7,9 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.Decimal64; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.codec.DecimalCodec; @@ -21,18 +21,18 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class DecimalCodecStringTest { +class DecimalCodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - DecimalCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(getType(), DecimalCodec.class); + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(getType(), DecimalCodec.class); assertEquals("123.456", codec.serialize(Decimal64.valueOf("123.456"))); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - DecimalCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(getType(), DecimalCodec.class); + void testDeserialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(getType(), DecimalCodec.class); assertEquals(Decimal64.valueOf("123.456"), codec.deserialize("123.456")); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/EmptyCodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/EmptyCodecStringTest.java index 8463474b66..16ec511f1d 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/EmptyCodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/EmptyCodecStringTest.java @@ -7,9 +7,9 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -19,22 +19,21 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class EmptyCodecStringTest { - +class EmptyCodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - EmptyCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class); + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class); - assertEquals("serialize", "", codec.serialize(Empty.value())); + assertEquals("", codec.serialize(Empty.value()), "serialize"); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - EmptyCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class); + void testDeserialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class); - assertEquals("deserialize", Empty.value(), codec.deserialize("")); + assertEquals(Empty.value(), codec.deserialize(""), "deserialize"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo"); } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/EnumCodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/EnumCodecStringTest.java index b9af6d6465..d1574b1695 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/EnumCodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/EnumCodecStringTest.java @@ -7,12 +7,12 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.data.api.codec.EnumCodec; /** @@ -20,21 +20,21 @@ import org.opendaylight.yangtools.yang.data.api.codec.EnumCodec; * * @author Thomas Pantelis */ -public class EnumCodecStringTest { +class EnumCodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - EnumCodec codec = getCodec(toEnumTypeDefinition("enum1", "enum2"), EnumCodec.class); - assertEquals("serialize", "enum1", codec.serialize("enum1")); + void testSerialize() { + final var codec = getCodec(toEnumTypeDefinition("enum1", "enum2"), EnumCodec.class); + assertEquals("enum1", codec.serialize("enum1"), "serialize"); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - EnumCodec codec = getCodec(toEnumTypeDefinition("enum1", "enum2"), EnumCodec.class); + void testDeserialize() { + final var codec = getCodec(toEnumTypeDefinition("enum1", "enum2"), EnumCodec.class); - assertEquals("deserialize", "enum1", codec.deserialize("enum1")); - assertEquals("deserialize", "enum2", codec.deserialize("enum2")); + assertEquals("enum1", codec.deserialize("enum1"), "deserialize"); + assertEquals("enum2", codec.deserialize("enum2"), "deserialize"); deserializeWithExpectedIllegalArgEx(codec, "enum3"); } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int16CodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int16CodecStringTest.java index 8771d9f418..b65f70bdca 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int16CodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int16CodecStringTest.java @@ -7,11 +7,11 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.data.api.codec.Int16Codec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -20,32 +20,32 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class Int16CodecStringTest { +class Int16CodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - Int16Codec codec = getCodec(BaseTypes.int16Type(), Int16Codec.class); - assertEquals("serialize", "10", codec.serialize(Short.valueOf((short) 10))); + void testSerialize() { + final var codec = getCodec(BaseTypes.int16Type(), Int16Codec.class); + assertEquals("10", codec.serialize(Short.valueOf((short) 10)), "serialize"); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - final String hexa = "+0X45c"; - final String negHexa = "-0X45c"; - final String octal = "02134"; - final String negOctal = "-02134"; - final String integer = "+1116"; - final String negInteger = "-1116"; + void testDeserialize() { + final var hexa = "+0X45c"; + final var negHexa = "-0X45c"; + final var octal = "02134"; + final var negOctal = "-02134"; + final var integer = "+1116"; + final var negInteger = "-1116"; - Int16Codec codec = getCodec(BaseTypes.int16Type(), Int16Codec.class); + final var codec = getCodec(BaseTypes.int16Type(), Int16Codec.class); - assertEquals("deserialize", codec.deserialize(hexa), Short.valueOf("+045c", 16)); - assertEquals("deserialize", codec.deserialize(negHexa), Short.valueOf("-045c", 16)); - assertEquals("deserialize", codec.deserialize(octal), Short.valueOf(octal, 8)); - assertEquals("deserialize", codec.deserialize(negOctal), Short.valueOf(negOctal, 8)); - assertEquals("deserialize", codec.deserialize(integer), Short.valueOf(integer, 10)); - assertEquals("deserialize", codec.deserialize(negInteger), Short.valueOf(negInteger, 10)); + assertEquals(codec.deserialize(hexa), Short.valueOf("+045c", 16), "deserialize"); + assertEquals(codec.deserialize(negHexa), Short.valueOf("-045c", 16), "deserialize"); + assertEquals(codec.deserialize(octal), Short.valueOf(octal, 8), "deserialize"); + assertEquals(codec.deserialize(negOctal), Short.valueOf(negOctal, 8), "deserialize"); + assertEquals(codec.deserialize(integer), Short.valueOf(integer, 10), "deserialize"); + assertEquals(codec.deserialize(negInteger), Short.valueOf(negInteger, 10), "deserialize"); deserializeWithExpectedIllegalArgEx(codec, "1o"); deserializeWithExpectedIllegalArgEx(codec, ""); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int32CodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int32CodecStringTest.java index 248900e56c..bef6a7a54b 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int32CodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int32CodecStringTest.java @@ -7,9 +7,9 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.data.api.codec.Int32Codec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -18,32 +18,32 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class Int32CodecStringTest { +class Int32CodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - Int32Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class); - assertEquals("serialize", "10", codec.serialize(Integer.valueOf(10))); + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class); + assertEquals("10", codec.serialize(Integer.valueOf(10)), "serialize"); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - final String hexa = "0x45FFFCDE"; - final String negHexa = "-0x45FFFCDE"; - final String octal = "010577776336"; - final String negOctal = "-010577776336"; - final String integer = "1174404318"; - final String negInteger = "-1174404318"; + void testDeserialize() { + final var hexa = "0x45FFFCDE"; + final var negHexa = "-0x45FFFCDE"; + final var octal = "010577776336"; + final var negOctal = "-010577776336"; + final var integer = "1174404318"; + final var negInteger = "-1174404318"; - Int32Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class); + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class); - assertEquals("deserialize", codec.deserialize(hexa), Integer.valueOf("+045FFFCDE", 16)); - assertEquals("deserialize", codec.deserialize(negHexa), Integer.valueOf("-045FFFCDE", 16)); - assertEquals("deserialize", codec.deserialize(octal), Integer.valueOf(octal, 8)); - assertEquals("deserialize", codec.deserialize(negOctal), Integer.valueOf(negOctal, 8)); - assertEquals("deserialize", codec.deserialize(integer), Integer.valueOf(integer, 10)); - assertEquals("deserialize", codec.deserialize(negInteger), Integer.valueOf(negInteger, 10)); + assertEquals(codec.deserialize(hexa), Integer.valueOf("+045FFFCDE", 16), "deserialize"); + assertEquals(codec.deserialize(negHexa), Integer.valueOf("-045FFFCDE", 16), "deserialize"); + assertEquals(codec.deserialize(octal), Integer.valueOf(octal, 8), "deserialize"); + assertEquals(codec.deserialize(negOctal), Integer.valueOf(negOctal, 8), "deserialize"); + assertEquals(codec.deserialize(integer), Integer.valueOf(integer, 10), "deserialize"); + assertEquals(codec.deserialize(negInteger), Integer.valueOf(negInteger, 10), "deserialize"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, ""); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int64CodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int64CodecStringTest.java index 784e4ba8ef..9ce04891c1 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int64CodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int64CodecStringTest.java @@ -7,11 +7,11 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.data.api.codec.Int64Codec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -20,33 +20,32 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class Int64CodecStringTest { - +class Int64CodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - Int64Codec codec = getCodec(BaseTypes.int64Type(), Int64Codec.class); - assertEquals("serialize", "12345", codec.serialize(Long.valueOf(12345))); + void testSerialize() { + final var codec = getCodec(BaseTypes.int64Type(), Int64Codec.class); + assertEquals("12345", codec.serialize(Long.valueOf(12345)), "serialize"); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - final String hexa = "0X75EDC78edCBA"; - final String negHexa = "-0X75EDC78edCBA"; - final String octal = "+03536670743556272"; - final String negOctal = "-03536670743556272"; - final String integer = "+129664115727546"; - final String negInteger = "-129664115727546"; - - Int64Codec codec = getCodec(BaseTypes.int64Type(), Int64Codec.class); - - assertEquals("deserialize", codec.deserialize(hexa), Long.valueOf("075EDC78edCBA", 16)); - assertEquals("deserialize", codec.deserialize(negHexa), Long.valueOf("-075EDC78edCBA", 16)); - assertEquals("deserialize", codec.deserialize(octal), Long.valueOf(octal, 8)); - assertEquals("deserialize", codec.deserialize(negOctal), Long.valueOf(negOctal, 8)); - assertEquals("deserialize", codec.deserialize(integer), Long.valueOf(integer, 10)); - assertEquals("deserialize", codec.deserialize(negInteger), Long.valueOf(negInteger, 10)); + void testDeserialize() { + final var hexa = "0X75EDC78edCBA"; + final var negHexa = "-0X75EDC78edCBA"; + final var octal = "+03536670743556272"; + final var negOctal = "-03536670743556272"; + final var integer = "+129664115727546"; + final var negInteger = "-129664115727546"; + + final var codec = getCodec(BaseTypes.int64Type(), Int64Codec.class); + + assertEquals(codec.deserialize(hexa), Long.valueOf("075EDC78edCBA", 16), "deserialize"); + assertEquals(codec.deserialize(negHexa), Long.valueOf("-075EDC78edCBA", 16), "deserialize"); + assertEquals(codec.deserialize(octal), Long.valueOf(octal, 8), "deserialize"); + assertEquals(codec.deserialize(negOctal), Long.valueOf(negOctal, 8), "deserialize"); + assertEquals(codec.deserialize(integer), Long.valueOf(integer, 10), "deserialize"); + assertEquals(codec.deserialize(negInteger), Long.valueOf(negInteger, 10), "deserialize"); deserializeWithExpectedIllegalArgEx(codec, "1234o"); deserializeWithExpectedIllegalArgEx(codec, ""); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int8CodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int8CodecStringTest.java index 325a776d50..518e5db275 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int8CodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Int8CodecStringTest.java @@ -7,9 +7,9 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -18,33 +18,33 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class Int8CodecStringTest { +class Int8CodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - Int8Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class); + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class); - assertEquals("serialize", "10", codec.serialize(Byte.valueOf((byte) 10))); + assertEquals("10", codec.serialize(Byte.valueOf((byte) 10)), "serialize"); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - final String hexa = "0x40"; - final String negHexa = "-0x40"; - final String octal = "+0100"; - final String negOctal = "-0100"; - final String integer = "64"; - final String negInteger = "-64"; - - Int8Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class); - - assertEquals("deserialize", codec.deserialize(hexa), Byte.valueOf("040", 16)); - assertEquals("deserialize", codec.deserialize(negHexa), Byte.valueOf("-040", 16)); - assertEquals("deserialize", codec.deserialize(octal), Byte.valueOf(octal, 8)); - assertEquals("deserialize", codec.deserialize(negOctal), Byte.valueOf(negOctal, 8)); - assertEquals("deserialize", codec.deserialize(integer), Byte.valueOf(integer, 10)); - assertEquals("deserialize", codec.deserialize(negInteger), Byte.valueOf(negInteger, 10)); + void testDeserialize() { + final var hexa = "0x40"; + final var negHexa = "-0x40"; + final var octal = "+0100"; + final var negOctal = "-0100"; + final var integer = "64"; + final var negInteger = "-64"; + + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class); + + assertEquals(codec.deserialize(hexa), Byte.valueOf("040", 16), "deserialize"); + assertEquals(codec.deserialize(negHexa), Byte.valueOf("-040", 16), "deserialize"); + assertEquals(codec.deserialize(octal), Byte.valueOf(octal, 8), "deserialize"); + assertEquals(codec.deserialize(negOctal), Byte.valueOf(negOctal, 8), "deserialize"); + assertEquals(codec.deserialize(integer), Byte.valueOf(integer, 10), "deserialize"); + assertEquals(codec.deserialize(negInteger), Byte.valueOf(negInteger, 10), "deserialize"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o"); TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, ""); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/StringCodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/StringCodecStringTest.java index 87be6d8452..b59f09701e 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/StringCodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/StringCodecStringTest.java @@ -7,53 +7,51 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.codec.StringCodec; import org.opendaylight.yangtools.yang.model.api.ConstraintMetaDefinition; import org.opendaylight.yangtools.yang.model.api.stmt.ValueRange; -import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; import org.opendaylight.yangtools.yang.model.ri.type.InvalidLengthConstraintException; import org.opendaylight.yangtools.yang.model.ri.type.RestrictedTypes; -import org.opendaylight.yangtools.yang.model.ri.type.StringTypeBuilder; /** * Unit tests for StringCodecString. * * @author Thomas Pantelis */ -public class StringCodecStringTest { +class StringCodecStringTest { @Test - public void testSerialize() { - StringCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.stringType(), + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.stringType(), StringCodec.class); - assertEquals("serialize", "foo", codec.serialize("foo")); - assertEquals("serialize", "", codec.serialize("")); + assertEquals("foo", codec.serialize("foo"), "serialize"); + assertEquals("", codec.serialize(""), "serialize"); } @Test - public void testDeserialize() { - StringCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.stringType(), + void testDeserialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.stringType(), StringCodec.class); - assertEquals("deserialize", "bar", codec.deserialize("bar")); - assertEquals("deserialize", "", codec.deserialize("")); + assertEquals("bar", codec.deserialize("bar"), "deserialize"); + assertEquals("", codec.deserialize(""), "deserialize"); } @Test - public void testDeserializeUnicode() throws InvalidLengthConstraintException { - final StringTypeBuilder builder = RestrictedTypes.newStringBuilder(BaseTypes.stringType(), + void testDeserializeUnicode() throws InvalidLengthConstraintException { + final var builder = RestrictedTypes.newStringBuilder(BaseTypes.stringType(), QName.create("foo", "foo")); builder.setLengthConstraint(mock(ConstraintMetaDefinition.class), List.of(ValueRange.of(1))); - final StringTypeDefinition type = builder.build(); + final var type = builder.build(); - StringCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec(type, StringCodec.class); + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(type, StringCodec.class); assertEquals("🌞", codec.deserialize("🌞")); } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/StringPatternCheckingCodecTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/StringPatternCheckingCodecTest.java index 88be76330b..838da98feb 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/StringPatternCheckingCodecTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/StringPatternCheckingCodecTest.java @@ -7,12 +7,12 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.XMLNamespace; @@ -21,9 +21,9 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; -public class StringPatternCheckingCodecTest { +class StringPatternCheckingCodecTest { @Test - public void testStringPatternCheckingCodec() { + void testStringPatternCheckingCodec() { final var schemaContext = YangParserTestUtils.parseYang(""" module string-pattern-checking-codec-test { namespace "string-pattern-checking-codec-test"; diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/TypeDefinitionAwareCodecTestHelper.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/TypeDefinitionAwareCodecTestHelper.java index 77c9fbf80b..fbbf00e980 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/TypeDefinitionAwareCodecTestHelper.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/TypeDefinitionAwareCodecTestHelper.java @@ -7,9 +7,8 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -20,29 +19,28 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; -import org.opendaylight.yangtools.yang.model.ri.type.EnumerationTypeBuilder; -public final class TypeDefinitionAwareCodecTestHelper { +final class TypeDefinitionAwareCodecTestHelper { private TypeDefinitionAwareCodecTestHelper() { // Hidden on purpose } - public static T getCodec(final TypeDefinition def, final Class clazz) { - TypeDefinitionAwareCodec codec = TypeDefinitionAwareCodec.fromType(def); - assertThat(codec, instanceOf(clazz)); + static T getCodec(final TypeDefinition def, final Class clazz) { + final var codec = TypeDefinitionAwareCodec.fromType(def); + assertInstanceOf(clazz, codec); return clazz.cast(codec); } - public static void deserializeWithExpectedIllegalArgEx(final IllegalArgumentCodec codec, + static void deserializeWithExpectedIllegalArgEx(final IllegalArgumentCodec codec, final @NonNull String param) { assertThrows(IllegalArgumentException.class, () -> codec.deserialize(param)); } - public static EnumTypeDefinition toEnumTypeDefinition(final String... enums) { - final EnumerationTypeBuilder b = BaseTypes.enumerationTypeBuilder(QName.create("foo", "foo")); - int val = 0; - for (String en : enums) { - EnumTypeDefinition.EnumPair mockEnum = mock(EnumPair.class); + static EnumTypeDefinition toEnumTypeDefinition(final String... enums) { + final var b = BaseTypes.enumerationTypeBuilder(QName.create("foo", "foo")); + var val = 0; + for (final var en : enums) { + final var mockEnum = mock(EnumPair.class); doReturn(en).when(mockEnum).getName(); doReturn(val).when(mockEnum).getValue(); b.addEnum(mockEnum); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint16CodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint16CodecStringTest.java index b677651609..9498895517 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint16CodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint16CodecStringTest.java @@ -7,11 +7,11 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.data.api.codec.Uint16Codec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -21,22 +21,22 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class Uint16CodecStringTest { +class Uint16CodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - Uint16Codec codec = getCodec(BaseTypes.uint16Type(), Uint16Codec.class); + void testSerialize() { + final var codec = getCodec(BaseTypes.uint16Type(), Uint16Codec.class); assertEquals("10", codec.serialize(Uint16.valueOf(10))); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - final String hexa = "0X45c"; - final String octal = "02134"; - final String integer = "1116"; + void testDeserialize() { + final var hexa = "0X45c"; + final var octal = "02134"; + final var integer = "1116"; - Uint16Codec codec = getCodec(BaseTypes.uint16Type(), Uint16Codec.class); + final var codec = getCodec(BaseTypes.uint16Type(), Uint16Codec.class); assertEquals(Uint16.valueOf("045c", 16), codec.deserialize(hexa)); assertEquals(Uint16.valueOf(octal, 8), codec.deserialize(octal)); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint32CodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint32CodecStringTest.java index 24640fac03..cfe3afbf4b 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint32CodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint32CodecStringTest.java @@ -7,11 +7,11 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.data.api.codec.Uint32Codec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -21,22 +21,22 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class Uint32CodecStringTest { +class Uint32CodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - Uint32Codec codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class); + void testSerialize() { + final var codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class); assertEquals("10", codec.serialize(Uint32.valueOf(10))); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - final String hexa = "0x45FFFCDE"; - final String octal = "010577776336"; - final String integer = "1174404318"; + void testDeserialize() { + final var hexa = "0x45FFFCDE"; + final var octal = "010577776336"; + final var integer = "1174404318"; - Uint32Codec codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class); + final var codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class); assertEquals(Uint32.valueOf("45FFFCDE", 16), codec.deserialize(hexa)); assertEquals(Uint32.valueOf(octal, 8), codec.deserialize(octal)); assertEquals(Uint32.valueOf(integer, 10), codec.deserialize(integer)); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint64CodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint64CodecStringTest.java index 33318b56ad..020327354d 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint64CodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint64CodecStringTest.java @@ -7,9 +7,9 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.Uint64; import org.opendaylight.yangtools.yang.data.api.codec.Uint64Codec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -19,23 +19,23 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class Uint64CodecStringTest { +class Uint64CodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - Uint64Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(), + void testSerialize() { + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(), Uint64Codec.class); assertEquals("123456789", codec.serialize(Uint64.valueOf(123456789))); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - final String hexa = "0X75EDC78edCBA"; - final String octal = "03536670743556272"; - final String integer = "129664115727546"; + void testDeserialize() { + final var hexa = "0X75EDC78edCBA"; + final var octal = "03536670743556272"; + final var integer = "129664115727546"; - Uint64Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(), + final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(), Uint64Codec.class); assertEquals(Uint64.valueOf("75EDC78edCBA", 16), codec.deserialize(hexa)); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint8CodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint8CodecStringTest.java index 526c86c0d5..efd86dc12e 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint8CodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/Uint8CodecStringTest.java @@ -7,11 +7,11 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.Uint8; import org.opendaylight.yangtools.yang.data.api.codec.Uint8Codec; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; @@ -21,22 +21,22 @@ import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; * * @author Thomas Pantelis */ -public class Uint8CodecStringTest { - @SuppressWarnings({ "unchecked" }) +class Uint8CodecStringTest { + @SuppressWarnings({"unchecked"}) @Test - public void testSerialize() { - Uint8Codec codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class); + void testSerialize() { + final var codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class); assertEquals("10", codec.serialize(Uint8.valueOf((short) 10))); } - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings({"unchecked"}) @Test - public void testDererialize() { - final String hexa = "0x40"; - final String octal = "0100"; - final String integer = "64"; + void testDererialize() { + final var hexa = "0x40"; + final var octal = "0100"; + final var integer = "64"; - Uint8Codec codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class); + final var codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class); assertEquals(Uint8.valueOf("040", 16), codec.deserialize(hexa)); assertEquals(Uint8.valueOf(octal, 8), codec.deserialize(octal)); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/UnionCodecStringTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/UnionCodecStringTest.java index bb02423d26..49640f9e73 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/UnionCodecStringTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/UnionCodecStringTest.java @@ -7,30 +7,29 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec; import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.codec.UnionCodec; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; -import org.opendaylight.yangtools.yang.model.ri.type.UnionTypeBuilder; /** * Unit tests forUnionCodecString. * * @author Thomas Pantelis */ -public class UnionCodecStringTest { +class UnionCodecStringTest { private static UnionTypeDefinition toUnionTypeDefinition(final TypeDefinition... types) { - final UnionTypeBuilder builder = BaseTypes.unionTypeBuilder(QName.create("foo", "foo")); + final var builder = BaseTypes.unionTypeBuilder(QName.create("foo", "foo")); - for (TypeDefinition t : types) { + for (final var t : types) { builder.addType(t); } @@ -39,29 +38,29 @@ public class UnionCodecStringTest { @SuppressWarnings("unchecked") @Test - public void testSerialize() { - UnionCodec codec = getCodec(toUnionTypeDefinition(toEnumTypeDefinition("enum1", "enum2"), + void testSerialize() { + final var codec = getCodec(toUnionTypeDefinition(toEnumTypeDefinition("enum1", "enum2"), toUnionTypeDefinition(BaseTypes.int32Type(),BaseTypes.int64Type()), BaseTypes.emptyType()), UnionCodec.class); - assertEquals("serialize", "enum1", codec.serialize("enum1")); - assertEquals("serialize", "123", codec.serialize("123")); - assertEquals("serialize", "123", codec.serialize(123)); - assertEquals("serialize", "", codec.serialize("")); + assertEquals("enum1", codec.serialize("enum1"), "serialize"); + assertEquals("123", codec.serialize("123"), "serialize"); + assertEquals("123", codec.serialize(123), "serialize"); + assertEquals("", codec.serialize(""), "serialize"); } @SuppressWarnings("unchecked") @Test - public void testDeserialize() { - UnionCodec codec = getCodec(toUnionTypeDefinition(toEnumTypeDefinition("enum1", "enum2"), + void testDeserialize() { + final var codec = getCodec(toUnionTypeDefinition(toEnumTypeDefinition("enum1", "enum2"), toUnionTypeDefinition(BaseTypes.int32Type(),BaseTypes.int64Type()), BaseTypes.emptyType()), UnionCodec.class); - assertEquals("deserialize", "enum1", codec.deserialize("enum1")); - assertEquals("deserialize", 123, codec.deserialize("123")); - assertEquals("deserialize", -123, codec.deserialize("-123")); - assertEquals("deserialize", 41234567890L, codec.deserialize("41234567890")); - assertEquals("deserialize", Empty.value(), codec.deserialize("")); + assertEquals("enum1", codec.deserialize("enum1"), "deserialize"); + assertEquals(123, codec.deserialize("123"), "deserialize"); + assertEquals(-123, codec.deserialize("-123"), "deserialize"); + assertEquals(41234567890L, codec.deserialize("41234567890"), "deserialize"); + assertEquals(Empty.value(), codec.deserialize(""), "deserialize"); deserializeWithExpectedIllegalArgEx(codec, "enum3"); deserializeWithExpectedIllegalArgEx(codec, "123o"); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1097Test.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1097Test.java index 60220246a2..e97f972ac4 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1097Test.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1097Test.java @@ -7,21 +7,18 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; -public class YT1097Test { +class YT1097Test { @Test - public void testBooleanStringUnion() { - final Module module = YangParserTestUtils.parseYang(""" + void testBooleanStringUnion() { + final var module = YangParserTestUtils.parseYang(""" module yt1097 { namespace yt1097; prefix yt1097; @@ -33,12 +30,11 @@ public class YT1097Test { } } }""").findModule("yt1097").orElseThrow(); - final DataSchemaNode foo = module.findDataChildByName(QName.create(module.getQNameModule(), "foo")) - .orElseThrow(); - assertThat(foo, instanceOf(LeafSchemaNode.class)); + final var foo = module.findDataChildByName(QName.create(module.getQNameModule(), "foo")).orElseThrow(); + assertInstanceOf(LeafSchemaNode.class, foo); - final TypeDefinitionAwareCodec codec = TypeDefinitionAwareCodec.from(((LeafSchemaNode) foo).getType()); - assertThat(codec, instanceOf(UnionStringCodec.class)); + final var codec = TypeDefinitionAwareCodec.from(((LeafSchemaNode) foo).getType()); + assertInstanceOf(UnionStringCodec.class, codec); assertDecoded(codec, Boolean.TRUE, "true"); assertDecoded(codec, Boolean.FALSE, "false"); @@ -54,8 +50,6 @@ public class YT1097Test { private static void assertDecoded(final TypeDefinitionAwareCodec codec, final Object expected, final String input) { - final Object result = codec.deserialize(input); - assertThat(result, instanceOf(expected.getClass())); - assertEquals(expected, result); + assertEquals(expected, assertInstanceOf(expected.getClass(), codec.deserialize(input))); } } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1437Test.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1437Test.java index 1559a8a2b4..25be626654 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1437Test.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1437Test.java @@ -7,18 +7,17 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; -public class YT1437Test { +class YT1437Test { @Test - public void testDecimalFractionDigits() { + void testDecimalFractionDigits() { final var module = YangParserTestUtils.parseYang(""" module yt1437 { namespace yt1437; @@ -32,22 +31,20 @@ public class YT1437Test { } }""").findModule("yt1437").orElseThrow(); final var foo = module.findDataChildByName(QName.create(module.getQNameModule(), "foo")).orElseThrow(); - assertThat(foo, instanceOf(LeafSchemaNode.class)); - final TypeDefinitionAwareCodec codec = TypeDefinitionAwareCodec.from(((LeafSchemaNode) foo).getType()); - assertThat(codec, instanceOf(DecimalStringCodec.class)); - final var cast = (DecimalStringCodec) codec; + final var codec = assertInstanceOf(DecimalStringCodec.class, + TypeDefinitionAwareCodec.from(assertInstanceOf(LeafSchemaNode.class, foo).getType())); - final var one = cast.deserialize("20.0"); + final var one = codec.deserialize("20.0"); assertEquals(2, one.scale()); - assertEquals("20.0", cast.serialize(one)); + assertEquals("20.0", codec.serialize(one)); - final var two = cast.deserialize("20.00"); + final var two = codec.deserialize("20.00"); assertEquals(2, two.scale()); - assertEquals("20.0", cast.serialize(two)); + assertEquals("20.0", codec.serialize(two)); - final var three = cast.deserialize("20.000"); + final var three = codec.deserialize("20.000"); assertEquals(2, three.scale()); - assertEquals("20.0", cast.serialize(three)); + assertEquals("20.0", codec.serialize(three)); } } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1442Test.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1442Test.java index bee70b55a0..711f24e308 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1442Test.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/YT1442Test.java @@ -7,15 +7,14 @@ */ package org.opendaylight.yangtools.yang.data.impl.codec; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -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.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; import org.eclipse.jdt.annotation.NonNull; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.Decimal64; import org.opendaylight.yangtools.yang.common.ErrorSeverity; import org.opendaylight.yangtools.yang.common.ErrorTag; @@ -25,11 +24,11 @@ import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; -public class YT1442Test { +class YT1442Test { private static DecimalStringCodec codec; - @BeforeClass - public static void beforeClass() { + @BeforeAll + static void beforeClass() { final var foo = YangParserTestUtils.parseYang(""" module yt1442 { namespace yt1442; @@ -46,68 +45,62 @@ public class YT1442Test { } }""") .getDataChildByName(QName.create("yt1442", "foo")); - assertThat(foo, instanceOf(LeafSchemaNode.class)); - - final TypeDefinitionAwareCodec tmp = TypeDefinitionAwareCodec.from(((LeafSchemaNode) foo).getType()); - assertThat(tmp, instanceOf(DecimalStringCodec.class)); - codec = (DecimalStringCodec) tmp; + codec = assertInstanceOf(DecimalStringCodec.class, + TypeDefinitionAwareCodec.from(assertInstanceOf(LeafSchemaNode.class, foo).getType())); } @Test - public void testTen() { + void testTen() { final var ten = codec.deserialize("10.00"); assertDecimal(1000, ten); assertEquals("10.0", codec.serialize(ten)); } @Test - public void testFifty() { + void testFifty() { final var fifty = codec.deserialize("50.00"); assertDecimal(5000, fifty); assertEquals("50.0", codec.serialize(fifty)); } @Test - public void testHundred() { + void testHundred() { final var hundred = codec.deserialize("100.00"); assertDecimal(10000, hundred); assertEquals("100.0", codec.serialize(hundred)); } @Test - public void testNegativeOutOfRange() { + void testNegativeOutOfRange() { assertYIVE("Value '-10.0' is not in required ranges [[10.0..100.0]]", "-10.00"); assertYIVE("Value '-50.0' is not in required ranges [[10.0..100.0]]", "-50.00"); assertYIVE("Value '-100.0' is not in required ranges [[10.0..100.0]]", "-100.00"); } @Test - public void testPositiveOutOfRange() { + void testPositiveOutOfRange() { assertYIVE("Value '9.99' is not in required ranges [[10.0..100.0]]", "9.99"); assertYIVE("Value '100.01' is not in required ranges [[10.0..100.0]]", "100.01"); } @Test - public void testTooLargeFractionPart() { + void testTooLargeFractionPart() { final var ex = assertThrows(IllegalArgumentException.class, () -> codec.deserialize("100.001")); assertEquals("Value '100.001' does not match required fraction-digits", ex.getMessage()); - final var cause = ex.getCause(); - assertThat(cause, instanceOf(ArithmeticException.class)); + final var cause = assertInstanceOf(ArithmeticException.class, ex.getCause()); assertEquals("Decreasing scale of 100.001 to 2 requires rounding", cause.getMessage()); } @Test - public void testTooLargeIntegralPart() { + void testTooLargeIntegralPart() { final var ex = assertThrows(IllegalArgumentException.class, () -> codec.deserialize("92233720368547759.0")); assertEquals("Value '92233720368547759.0' does not match required fraction-digits", ex.getMessage()); - final var cause = ex.getCause(); - assertThat(cause, instanceOf(ArithmeticException.class)); + final var cause = assertInstanceOf(ArithmeticException.class, ex.getCause()); assertEquals("Increasing scale of 92233720368547759.0 to 2 would overflow", cause.getMessage()); } private static void assertDecimal(final long unscaledValue, final Object obj) { - assertThat(obj, instanceOf(Decimal64.class)); - final var actual = (Decimal64) obj; + final var actual = assertInstanceOf(Decimal64.class, obj); assertEquals(2, actual.scale()); assertEquals(unscaledValue, actual.unscaledValue()); } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java index bab06ecc21..b9e60a3e23 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java @@ -8,34 +8,20 @@ package org.opendaylight.yangtools.yang.data.impl.schema; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.LinkedList; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.util.UnmodifiableCollection; +import java.util.List; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode; -import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode; -import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; -import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode; import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode; -import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder; @@ -46,14 +32,8 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUn import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; -public class BuilderTest { +class BuilderTest { private static final QName ROOT_CONTAINER = QName.create("test.namespace.builder.test", "2016-01-01", "root-container"); private static final QName LIST_MAIN = QName.create(ROOT_CONTAINER, "list-ordered-by-user-with-key"); @@ -71,69 +51,28 @@ public class BuilderTest { private static final int SIZE = 3; private static final NodeWithValue BAR_PATH = new NodeWithValue<>(LEAF_LIST_MAIN, "bar"); private static final LeafSetEntryNode LEAF_SET_ENTRY_NODE = - ImmutableLeafSetEntryNodeBuilder.create() - .withNodeIdentifier(BAR_PATH) - .withValue("bar") - .build(); - private ListSchemaNode list; - private LeafListSchemaNode leafList; - - @Before - public void setup() throws URISyntaxException { - final var schema = YangParserTestUtils.parseYang(""" - module immutable-ordered-map-node { - yang-version 1; - namespace "test.namespace.builder.test"; - prefix "iomn"; - - revision "2016-01-01" { - description "Initial revision."; - } - - container root-container { - list list-ordered-by-user-with-key { - key "leaf-a"; - ordered-by "user"; - leaf leaf-a { - type string; - } - } - leaf-list leaf-list-ordered-by-user { - ordered-by "user"; - type string; - } - } - }"""); - final Module module = schema.getModules().iterator().next(); - final DataSchemaNode root = module.getDataChildByName(ROOT_CONTAINER); - list = (ListSchemaNode)((ContainerSchemaNode) root).getDataChildByName(LIST_MAIN); - leafList = (LeafListSchemaNode)((ContainerSchemaNode) root).getDataChildByName(LEAF_LIST_MAIN); - } + ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(BAR_PATH).withValue("bar").build(); @Test - public void immutableOrderedMapBuilderTest() { - final var mapEntryNodeColl = new LinkedList(); - mapEntryNodeColl.add(LIST_MAIN_CHILD_3); - final var keys = new HashMap(); - keys.put(LIST_MAIN_CHILD_QNAME_1, 1); - final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(LIST_MAIN, keys); - final UserMapNode orderedMapNodeCreateNull = ImmutableUserMapNodeBuilder.create() + void immutableOrderedMapBuilderTest() { + final var mapEntryPath = NodeIdentifierWithPredicates.of(LIST_MAIN, LIST_MAIN_CHILD_QNAME_1, 1); + final var orderedMapNodeCreateNull = ImmutableUserMapNodeBuilder.create() .withNodeIdentifier(NODE_IDENTIFIER_LIST) .withChild(LIST_MAIN_CHILD_1) .addChild(LIST_MAIN_CHILD_2) - .withValue(mapEntryNodeColl) + .withValue(List.of(LIST_MAIN_CHILD_3)) .build(); - final UserMapNode orderedMapNodeCreateSize = ImmutableUserMapNodeBuilder.create(SIZE) + final var orderedMapNodeCreateSize = ImmutableUserMapNodeBuilder.create(SIZE) .withNodeIdentifier(NODE_IDENTIFIER_LIST) .build(); - final UserMapNode orderedMapNodeCreateNode = ImmutableUserMapNodeBuilder.create(orderedMapNodeCreateNull) + final var orderedMapNodeCreateNode = ImmutableUserMapNodeBuilder.create(orderedMapNodeCreateNull) .removeChild(mapEntryPath) .build(); - final UserMapNode orderedMapNodeSchemaAware = ImmutableUserMapNodeBuilder.create() + final var orderedMapNodeSchemaAware = ImmutableUserMapNodeBuilder.create() .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) .withChild(LIST_MAIN_CHILD_1) .build(); - final UserMapNode orderedMapNodeSchemaAwareMapNodeConst = + final var orderedMapNodeSchemaAwareMapNodeConst = ImmutableUserMapNodeBuilder.create(getImmutableUserMapNode()) .build(); @@ -146,73 +85,64 @@ public class BuilderTest { } @Test - public void immutableUserLeafSetNodeBuilderTest() { - final UserLeafSetNode orderedLeafSet = ImmutableUserLeafSetNodeBuilder.create() + void immutableUserLeafSetNodeBuilderTest() { + final var orderedLeafSet = ImmutableUserLeafSetNodeBuilder.create() .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) .withChild(LEAF_SET_ENTRY_NODE) .withChildValue("baz") .removeChild(BAR_PATH) .build(); - final LinkedList> mapEntryNodeColl = new LinkedList<>(); - mapEntryNodeColl.add(orderedLeafSet); - final UnmodifiableCollection leafSetCollection = (UnmodifiableCollection)orderedLeafSet.body(); - final NormalizedNode orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeBuilder.create() + final var orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeBuilder.create() .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) .withChildValue("baz") .build(); - final UnmodifiableCollection SchemaAwareleafSetCollection = - (UnmodifiableCollection) orderedMapNodeSchemaAware.body(); assertNotNull(Builders.anyXmlBuilder()); - assertEquals(1, ((UserLeafSetNode)orderedLeafSet).size()); + assertEquals(1, orderedLeafSet.size()); assertEquals("baz", orderedLeafSet.childAt(0).body()); assertNull(orderedLeafSet.childByArg(BAR_PATH)); - assertEquals(1, leafSetCollection.size()); - assertEquals(1, SchemaAwareleafSetCollection.size()); + assertEquals(1, orderedLeafSet.size()); + assertEquals(1, orderedMapNodeSchemaAware.size()); } @Test - public void immutableMapNodeBuilderTest() { - final LinkedList mapEntryNodeColl = new LinkedList<>(); - mapEntryNodeColl.add(LIST_MAIN_CHILD_3); - final CollectionNodeBuilder collectionNodeBuilder = - ImmutableMapNodeBuilder.create(1); - assertNotNull(collectionNodeBuilder); - collectionNodeBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST); - collectionNodeBuilder.withValue(mapEntryNodeColl); - final SystemMapNode mapNode = collectionNodeBuilder.build(); + void immutableMapNodeBuilderTest() { + final var mapNode = ImmutableMapNodeBuilder.create(1) + .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) + .withValue(List.of(LIST_MAIN_CHILD_3)) + .build(); assertNotNull(Builders.mapBuilder(mapNode)); } @Test - public void immutableUnkeyedListEntryNodeBuilderTest() { - final UnkeyedListEntryNode unkeyedListEntryNode = ImmutableUnkeyedListEntryNodeBuilder.create() + void immutableUnkeyedListEntryNodeBuilderTest() { + final var unkeyedListEntryNode = ImmutableUnkeyedListEntryNodeBuilder.create() .withNodeIdentifier(NODE_IDENTIFIER_LIST) .build(); - final UnkeyedListEntryNode unkeyedListEntryNodeSize = ImmutableUnkeyedListEntryNodeBuilder.create(1) + final var unkeyedListEntryNodeSize = ImmutableUnkeyedListEntryNodeBuilder.create(1) .withNodeIdentifier(NODE_IDENTIFIER_LIST) .build(); - final UnkeyedListEntryNode unkeyedListEntryNodeNode = ImmutableUnkeyedListEntryNodeBuilder + final var unkeyedListEntryNodeNode = ImmutableUnkeyedListEntryNodeBuilder .create(unkeyedListEntryNode).build(); assertEquals(unkeyedListEntryNode.name(), unkeyedListEntryNodeSize.name()); assertEquals(unkeyedListEntryNodeSize.name(), unkeyedListEntryNodeNode.name()); } @Test - public void immutableUnkeyedListNodeBuilderTest() { - final UnkeyedListEntryNode unkeyedListEntryNode = ImmutableUnkeyedListEntryNodeBuilder.create() + void immutableUnkeyedListNodeBuilderTest() { + final var unkeyedListEntryNode = ImmutableUnkeyedListEntryNodeBuilder.create() .withNodeIdentifier(NODE_IDENTIFIER_LEAF) .build(); - final ImmutableUnkeyedListNodeBuilder immutableUnkeyedListNodeBuilder = (ImmutableUnkeyedListNodeBuilder) + final var immutableUnkeyedListNodeBuilder = (ImmutableUnkeyedListNodeBuilder) ImmutableUnkeyedListNodeBuilder.create(); - final UnkeyedListNode unkeyedListNode = immutableUnkeyedListNodeBuilder + final var unkeyedListNode = immutableUnkeyedListNodeBuilder .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) .addChild(unkeyedListEntryNode) .build(); - final UnkeyedListNode unkeyedListNodeSize = ImmutableUnkeyedListNodeBuilder.create(1) + final var unkeyedListNodeSize = ImmutableUnkeyedListNodeBuilder.create(1) .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) .build(); - final UnkeyedListNode unkeyedListNodeCreated = ImmutableUnkeyedListNodeBuilder.create(unkeyedListNode) + final var unkeyedListNodeCreated = ImmutableUnkeyedListNodeBuilder.create(unkeyedListNode) .build(); assertThrows(IndexOutOfBoundsException.class, () -> unkeyedListNodeSize.childAt(1)); @@ -224,48 +154,41 @@ public class BuilderTest { } @Test - public void immutableChoiceNodeBuilderTest() { - final ChoiceNode choiceNode = ImmutableChoiceNodeBuilder.create(1).withNodeIdentifier(NODE_IDENTIFIER_LIST) + void immutableChoiceNodeBuilderTest() { + final var choiceNode = ImmutableChoiceNodeBuilder.create(1).withNodeIdentifier(NODE_IDENTIFIER_LIST) .build(); - final ChoiceNode choiceNodeCreated = ImmutableChoiceNodeBuilder.create(choiceNode).build(); + final var choiceNodeCreated = ImmutableChoiceNodeBuilder.create(choiceNode).build(); assertEquals(choiceNodeCreated.name(), choiceNode.name()); } @Test - public void immutableContainerNodeBuilderExceptionTest() { - final ContainerNode immutableContainerNode = ImmutableContainerNodeBuilder.create(1) + void immutableContainerNodeBuilderExceptionTest() { + final var immutableContainerNode = ImmutableContainerNodeBuilder.create(1) .withNodeIdentifier(NODE_IDENTIFIER_LIST) .build(); assertNotNull(immutableContainerNode); } @Test - public void immutableLeafSetNodeBuilderExceptionTest() { - final SystemLeafSetNode leafSetNode = ImmutableLeafSetNodeBuilder.create(1) + void immutableLeafSetNodeBuilderExceptionTest() { + final var leafSetNode = ImmutableLeafSetNodeBuilder.create(1) .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) .build(); assertNotNull(leafSetNode); } @Test - public void immutableMapEntryNodeBuilderExceptionTest() { + void immutableMapEntryNodeBuilderExceptionTest() { final var builder = ImmutableMapEntryNodeBuilder.create(1); assertThrows(NullPointerException.class, builder::build); } @Test - public void immutableUnkeyedListNodeBuilderExceptionTest() { + void immutableUnkeyedListNodeBuilderExceptionTest() { final var builder = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF); assertThrows(UnsupportedOperationException.class, () -> builder.removeChild(NODE_IDENTIFIER_LIST)); } - private static SystemMapNode getImmutableMapNode() { - return ImmutableMapNodeBuilder.create() - .withNodeIdentifier(NODE_IDENTIFIER_LIST) - .withChild(LIST_MAIN_CHILD_1) - .build(); - } - private static UserMapNode getImmutableUserMapNode() { return ImmutableUserMapNodeBuilder.create() .withNodeIdentifier(NODE_IDENTIFIER_LIST) diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriterTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriterTest.java index 9d48b9fca4..be8a3d2e9c 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriterTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriterTest.java @@ -7,16 +7,14 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; -import java.text.ParseException; import java.util.List; import java.util.Map; import javax.xml.transform.dom.DOMSource; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.Revision; @@ -27,7 +25,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithV import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -public class ImmutableNormalizedNodeStreamWriterTest { +class ImmutableNormalizedNodeStreamWriterTest { private QNameModule bazModule; @@ -64,8 +62,8 @@ public class ImmutableNormalizedNodeStreamWriterTest { private DOMSource anyxmlDomSource; - @Before - public void setup() throws ParseException { + @Test + void testImmutableNormalizedNodeStreamWriter() throws IOException { bazModule = QNameModule.create(XMLNamespace.of("baz-namespace"), Revision.of("1970-01-01")); outerContainer = QName.create(bazModule, "outer-container"); @@ -100,10 +98,7 @@ public class ImmutableNormalizedNodeStreamWriterTest { myLeafInList3 = QName.create(bazModule, "my-leaf-in-list-3"); anyxmlDomSource = new DOMSource(); - } - @Test - public void testImmutableNormalizedNodeStreamWriter() throws IOException { final var result = new NormalizationResultHolder(); final var immutableNormalizedNodeStreamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final var normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(immutableNormalizedNodeStreamWriter); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java index 3827b5a413..9a89ef3b92 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java @@ -7,31 +7,27 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.isA; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import com.google.common.collect.ImmutableMap; -import java.util.Collection; import java.util.Map; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.util.ImmutableOffsetMap; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; -public class InstanceIdToNodesTest { +class InstanceIdToNodesTest { private static final String NS = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:normalization:test"; private static final String REVISION = "2014-03-13"; @@ -50,18 +46,18 @@ public class InstanceIdToNodesTest { private final NodeIdentifier leafList = new NodeIdentifier(QName.create(NS, REVISION, "ordered-leaf-list")); private final NodeWithValue leafListWithValue = new NodeWithValue<>(leafList.getNodeType(), "abcd"); - @BeforeClass - public static void setUp() { + @BeforeAll + static void setUp() { ctx = YangParserTestUtils.parseYangResources(InstanceIdToNodesTest.class, "/filter-test.yang"); } - @AfterClass - public static void teardown() { + @AfterAll + static void teardown() { ctx = null; } @Test - public void testListLastChildOverride() { + void testListLastChildOverride() { assertEquals(Builders.containerBuilder() .withNodeIdentifier(rootContainer) .withChild(Builders.mapBuilder() @@ -79,7 +75,7 @@ public class InstanceIdToNodesTest { } @Test - public void testLeafList() { + void testLeafList() { assertEquals(Builders.containerBuilder() .withNodeIdentifier(rootContainer) .withChild(Builders.orderedLeafSetBuilder() @@ -94,22 +90,21 @@ public class InstanceIdToNodesTest { } @Test - public void testEmptyInstanceIdentifier() { + void testEmptyInstanceIdentifier() { assertEquals(ImmutableNodes.containerNode(SchemaContext.NAME), ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.of())); } @Test - public void testKeyOrdering() { + void testKeyOrdering() { final Map misordered = ImmutableOffsetMap.orderedCopyOf(ImmutableMap.of(BAR, "bar", FOO, "foo")); - final NodeIdentifierWithPredicates id = NodeIdentifierWithPredicates.of(TWO_KEY_LIST.getNodeType(), misordered); + final var id = NodeIdentifierWithPredicates.of(TWO_KEY_LIST.getNodeType(), misordered); assertArrayEquals(new Object[] { BAR, FOO }, id.keySet().toArray()); - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.of(TWO_KEY_LIST, id)); - assertThat(filter, isA(MapNode.class)); - final Collection value = ((MapNode) filter).body(); + final var filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.of(TWO_KEY_LIST, id)); + final var value = assertInstanceOf(MapNode.class, filter).body(); assertEquals(1, value.size()); - final MapEntryNode entry = value.iterator().next(); + final var entry = value.iterator().next(); // The entry must have a the proper order assertArrayEquals(new Object[] { FOO, BAR }, entry.name().keySet().toArray()); diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java index c77fc1c049..686d46effc 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java @@ -7,64 +7,55 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema; -import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.XMLNamespace; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder; -public class NormalizedDataBuilderTest { +class NormalizedDataBuilderTest { @Test - public void testSchemaUnaware() { + void testSchemaUnaware() { // Container - DataContainerNodeBuilder builder = Builders - .containerBuilder().withNodeIdentifier(getNodeIdentifier("container")); - - // leaf - LeafNode leafChild = Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("leaf")) - .withValue("String").build(); - builder.withChild(leafChild); - - // leafList - LeafSetNode leafList = Builders.leafSetBuilder() + final var builder = Builders.containerBuilder() + .withNodeIdentifier(getNodeIdentifier("container")) + .withChild(Builders.leafBuilder() + .withNodeIdentifier(getNodeIdentifier("leaf")) + .withValue("String") + .build()) + .withChild(Builders.leafSetBuilder() .withNodeIdentifier(getNodeIdentifier("leaf")) .withChildValue(1) .withChild(Builders.leafSetEntryBuilder() - .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build()) - .build(); - builder.withChild(leafList); - - // list - MapEntryNode listChild1 = Builders - .mapEntryBuilder() - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList")) - .withValue(1).build()) - .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build()) - .withNodeIdentifier(NodeIdentifierWithPredicates.of( - getNodeIdentifier("list").getNodeType(), Collections.singletonMap( - getNodeIdentifier("uint32InList").getNodeType(), 1))).build(); - - builder + .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)) + .withValue(3) + .build()) + .build()) .withChild(Builders.mapBuilder() .withNodeIdentifier(getNodeIdentifier("list")) - .withChild(listChild1) + .withChild(Builders.mapEntryBuilder() + .withChild(Builders.leafBuilder() + .withNodeIdentifier(getNodeIdentifier("uint32InList")) + .withValue(1) + .build()) + .withChild(Builders.containerBuilder() + .withNodeIdentifier(getNodeIdentifier("containerInList")) + .build()) + .withNodeIdentifier(NodeIdentifierWithPredicates.of(getNodeIdentifier("list").getNodeType(), + getNodeIdentifier("uint32InList").getNodeType(), 1)) + .build()) .build()) .withChild(Builders.leafBuilder() .withNodeIdentifier(getNodeIdentifier("augmentUint32")) - .withValue(11).build()); + .withValue(11) + .build()); - // This works without schema (adding child from augment as a direct - // child) - builder.withChild(Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32")) - .withValue(11).build()); + // This works without schema (adding child from augment as a direct child) + builder.withChild(Builders.leafBuilder() + .withNodeIdentifier(getNodeIdentifier("augmentUint32")) + .withValue(11) + .build()); } private static NodeWithValue getNodeWithValueIdentifier(final String localName, final T value) { diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeUtilsTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeUtilsTest.java index 879b010317..8bd551bc8b 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeUtilsTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeUtilsTest.java @@ -8,14 +8,13 @@ package org.opendaylight.yangtools.yang.data.impl.schema; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; -import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; @@ -24,30 +23,29 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; /* - * Schema structure of document is: - * - * container root {  - * list list-a { - * key leaf-a; - * leaf leaf-a; - * choice choice-a { - * case one { - * leaf one; - * } - * case two-three { - * leaf two; - * leaf three; - * } - * } - * list list-b { - * key leaf-b; - * leaf leaf-b; - * } - * } - * } - */ -public class NormalizedNodeUtilsTest { - +* Schema structure of document is: +* +* container root {  +* list list-a { +* key leaf-a; +* leaf leaf-a; +* choice choice-a { +* case one { +* leaf one; +* } +* case two-three { +* leaf two; +* leaf three; +* } +* } +* list list-b { +* key leaf-b; +* leaf leaf-b; +* } +* } +* } +*/ +class NormalizedNodeUtilsTest { private static final QName ROOT_QNAME = QName.create("urn:opendaylight:controller:sal:dom:store:test", "2014-03-13", "root"); private static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a"); @@ -60,15 +58,15 @@ public class NormalizedNodeUtilsTest { private static final String TWO = "two"; private static final YangInstanceIdentifier LIST_A_FOO_PATH = YangInstanceIdentifier.builder() - .node(LIST_A_QNAME) - .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, FOO) - .build(); + .node(LIST_A_QNAME) + .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, FOO) + .build(); private static final YangInstanceIdentifier LIST_B_TWO_PATH = YangInstanceIdentifier.builder() - .node(LIST_A_QNAME) - .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, BAR) - .node(LIST_B_QNAME) - .nodeWithKey(LIST_B_QNAME,LEAF_B_QNAME,TWO) - .build(); + .node(LIST_A_QNAME) + .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, BAR) + .node(LIST_B_QNAME) + .nodeWithKey(LIST_B_QNAME,LEAF_B_QNAME,TWO) + .build(); /** * Returns a test document. @@ -89,30 +87,29 @@ public class NormalizedNodeUtilsTest { * @return A test document */ private static NormalizedNode createDocumentOne() { - return ImmutableContainerNodeBuilder - .create() - .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME)) - .withChild( - mapNodeBuilder(LIST_A_QNAME) - .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, FOO)) - .withChild( - mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, BAR).withChild( - mapNodeBuilder(LIST_B_QNAME) - .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, ONE)) - .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, TWO)).build()) - .build()).build()).build(); - + return ImmutableContainerNodeBuilder.create() + .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME)) + .withChild(mapNodeBuilder(LIST_A_QNAME) + .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, FOO)) + .withChild(mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, BAR) + .withChild(mapNodeBuilder(LIST_B_QNAME) + .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, ONE)) + .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, TWO)) + .build()) + .build()) + .build()) + .build(); } @Test - public void findNodeTest() { - NormalizedNode tree = createDocumentOne(); + void findNodeTest() { + final var tree = createDocumentOne(); assertNotNull(tree); - Optional listFooResult = NormalizedNodes.findNode(tree, LIST_A_FOO_PATH); + final var listFooResult = NormalizedNodes.findNode(tree, LIST_A_FOO_PATH); assertTrue(listFooResult.isPresent()); - Optional listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH); + final var listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH); assertTrue(listTwoResult.isPresent()); } } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/OrderingEqualityTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/OrderingEqualityTest.java index afd051d730..5a2ef01cf0 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/OrderingEqualityTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/OrderingEqualityTest.java @@ -7,25 +7,22 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema; -import static org.junit.Assert.assertArrayEquals; -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.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode; -import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode; -public class OrderingEqualityTest { +class OrderingEqualityTest { private static final QName FOO = QName.create("foo", "foo"); private static final QName BAR = QName.create("foo", "bar"); @Test - public void testUserMap() { - final UserMapNode firstMap = Builders.orderedMapBuilder() + void testUserMap() { + final var firstMap = Builders.orderedMapBuilder() .withNodeIdentifier(new NodeIdentifier(FOO)) .withChild(Builders.mapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")) @@ -37,7 +34,7 @@ public class OrderingEqualityTest { .build()) .build(); - final UserMapNode secondMap = Builders.orderedMapBuilder() + final var secondMap = Builders.orderedMapBuilder() .withNodeIdentifier(new NodeIdentifier(FOO)) .withChild(Builders.mapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")) @@ -50,10 +47,10 @@ public class OrderingEqualityTest { .build(); assertEquals(firstMap.asMap(), secondMap.asMap()); - assertFalse(firstMap.equals(secondMap)); - assertFalse(secondMap.equals(firstMap)); + assertNotEquals(firstMap, secondMap); + assertNotEquals(secondMap, firstMap); - final UserMapNode thirdMap = Builders.orderedMapBuilder() + final var thirdMap = Builders.orderedMapBuilder() .withNodeIdentifier(new NodeIdentifier(FOO)) .withChild(Builders.mapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")) @@ -66,13 +63,13 @@ public class OrderingEqualityTest { .build(); assertEquals(secondMap.asMap(), thirdMap.asMap()); - assertFalse(firstMap.equals(thirdMap)); - assertTrue(secondMap.equals(thirdMap)); + assertNotEquals(firstMap, thirdMap); + assertEquals(secondMap, thirdMap); assertArrayEquals(secondMap.body().toArray(), thirdMap.body().toArray()); assertEquals(secondMap.hashCode(), thirdMap.hashCode()); // Although this map looks as secondMap, it is not equal - final SystemMapNode systemMap = Builders.mapBuilder() + final var systemMap = Builders.mapBuilder() .withNodeIdentifier(new NodeIdentifier(FOO)) .withChild(Builders.mapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")) @@ -85,13 +82,13 @@ public class OrderingEqualityTest { .build(); assertEquals(secondMap.asMap(), systemMap.asMap()); - assertFalse(firstMap.equals(systemMap)); - assertFalse(secondMap.equals(systemMap)); + assertNotEquals(firstMap, systemMap); + assertNotEquals(secondMap, systemMap); } @Test - public void testSystemMap() { - final SystemMapNode firstMap = Builders.mapBuilder() + void testSystemMap() { + final var firstMap = Builders.mapBuilder() .withNodeIdentifier(new NodeIdentifier(FOO)) .withChild(Builders.mapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")) @@ -102,7 +99,7 @@ public class OrderingEqualityTest { .withChild(ImmutableNodes.leafNode(BAR, "two")) .build()) .build(); - final SystemMapNode secondMap = Builders.mapBuilder() + final var secondMap = Builders.mapBuilder() .withNodeIdentifier(new NodeIdentifier(FOO)) .withChild(Builders.mapEntryBuilder() .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")) @@ -116,8 +113,8 @@ public class OrderingEqualityTest { assertEquals(firstMap.asMap(), secondMap.asMap()); // Order does not matter - assertTrue(firstMap.equals(secondMap)); - assertTrue(secondMap.equals(firstMap)); + assertEquals(firstMap, secondMap); + assertEquals(secondMap, firstMap); assertEquals(firstMap.hashCode(), secondMap.hashCode()); } } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNodeTest.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNodeTest.java index 92b4ae43cb..288a4e565a 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNodeTest.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNodeTest.java @@ -7,15 +7,14 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema.nodes; -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.assertNotEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -public class AbstractImmutableNormalizedValueAttrNodeTest { +class AbstractImmutableNormalizedValueAttrNodeTest { private record TestValue(int value) { // Simple enough } @@ -28,257 +27,257 @@ public class AbstractImmutableNormalizedValueAttrNodeTest { @Test // This test is based on using different references; we're testing equals() @SuppressWarnings({"RedundantStringConstructorCall", "EqualsWithItself"}) - public void equalsByteTest() { - byte[] value = "test".getBytes(); - byte[] equalValue = "test".getBytes(); + void equalsByteTest() { + final var value = "test".getBytes(); + final var equalValue = "test".getBytes(); - LeafNode leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value); - LeafNode equalLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue); + final var leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value); + final var equalLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue); - assertTrue(leafNode.equals(leafNode)); - assertTrue(leafNode.equals(equalLeafNode)); - assertTrue(equalLeafNode.equals(leafNode)); + assertEquals(leafNode, leafNode); + assertEquals(leafNode, equalLeafNode); + assertEquals(equalLeafNode, leafNode); - TestValue[] value2 = new TestValue[] { new TestValue(1), new TestValue(2) }; - TestValue[] equalValue2 = new TestValue[] { new TestValue(1), new TestValue(2) }; + final var value2 = new TestValue[] { new TestValue(1), new TestValue(2) }; + final var equalValue2 = new TestValue[] { new TestValue(1), new TestValue(2) }; - LeafNode leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2); - LeafNode equalLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue2); + final var leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2); + final var equalLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue2); - assertTrue(leafNode2.equals(leafNode2)); - assertTrue(leafNode2.equals(equalLeafNode2)); - assertTrue(equalLeafNode2.equals(leafNode2)); + assertEquals(leafNode2, leafNode2); + assertEquals(leafNode2, equalLeafNode2); + assertEquals(equalLeafNode2, leafNode2); - byte[][] value3 = new byte[][] { "test".getBytes(), "test2".getBytes() }; - byte[][] equalValue3 = new byte[][] { "test".getBytes(), "test2".getBytes() }; + final var value3 = new byte[][] { "test".getBytes(), "test2".getBytes() }; + final var equalValue3 = new byte[][] { "test".getBytes(), "test2".getBytes() }; - LeafNode leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, + final var leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3); - LeafNode equalLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue3); + final var equalLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue3); - assertTrue(leafNode3.equals(leafNode3)); - assertTrue(leafNode3.equals(equalLeafNode3)); - assertTrue(equalLeafNode3.equals(leafNode3)); + assertEquals(leafNode3, leafNode3); + assertEquals(leafNode3, equalLeafNode3); + assertEquals(equalLeafNode3, leafNode3); - TestValue[][] value4 = new TestValue[][] { + final var value4 = new TestValue[][] { new TestValue[] { new TestValue(1), new TestValue(2) }, new TestValue[] { new TestValue(3), new TestValue(4) }, }; - TestValue[][] equalValue4 = new TestValue[][] { + final var equalValue4 = new TestValue[][] { new TestValue[] { new TestValue(1), new TestValue(2) }, new TestValue[] { new TestValue(3), new TestValue(4) }, }; - LeafNode leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME,value4); - LeafNode equalLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue4); + final var leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME,value4); + final var equalLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue4); - assertTrue(leafNode4.equals(leafNode4)); - assertTrue(leafNode4.equals(equalLeafNode4)); - assertTrue(equalLeafNode4.equals(leafNode4)); + assertEquals(leafNode4, leafNode4); + assertEquals(leafNode4, equalLeafNode4); + assertEquals(equalLeafNode4, leafNode4); - TestValue value6 = new TestValue(1); - TestValue equalValue6 = new TestValue(1); + final var value6 = new TestValue(1); + final var equalValue6 = new TestValue(1); - LeafNode leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6); - LeafNode equalLeafNode6 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue6); + final var leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6); + final var equalLeafNode6 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue6); - assertTrue(leafNode6.equals(leafNode6)); - assertTrue(leafNode6.equals(equalLeafNode6)); - assertTrue(equalLeafNode6.equals(leafNode6)); + assertEquals(leafNode6, leafNode6); + assertEquals(leafNode6, equalLeafNode6); + assertEquals(equalLeafNode6, leafNode6); - String value5 = "test"; - String equalValue5 = new String("test"); + final var value5 = "test"; + final var equalValue5 = new String("test"); - LeafNode leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5); - LeafNode equalLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue5); + final var leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5); + final var equalLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue5); - assertTrue(leafNode5.equals(leafNode5)); - assertTrue(leafNode5.equals(equalLeafNode5)); - assertTrue(equalLeafNode5.equals(leafNode5)); + assertEquals(leafNode5, leafNode5); + assertEquals(leafNode5, equalLeafNode5); + assertEquals(equalLeafNode5, leafNode5); } @Test // We're testing equals() @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"}) - public void notEqualByteTest() { + void notEqualByteTest() { - byte[] value = "test".getBytes(); - byte[] equalValue = "test".getBytes(); + final var value = "test".getBytes(); + final var equalValue = "test".getBytes(); - LeafNode leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value); - LeafNode otherLeafNode = ImmutableNodes.leafNode(OTHER_LEAF_QNAME, equalValue); + final var leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value); + final var otherLeafNode = ImmutableNodes.leafNode(OTHER_LEAF_QNAME, equalValue); - assertFalse(leafNode.equals(null)); - assertFalse(leafNode.equals(new Object())); - assertFalse(leafNode.equals(otherLeafNode)); - assertFalse(otherLeafNode.equals(leafNode)); + assertNotEquals(null, leafNode); + assertNotEquals(leafNode, new Object()); + assertNotEquals(leafNode, otherLeafNode); + assertNotEquals(otherLeafNode, leafNode); - byte[] value1 = "test".getBytes(); - byte[] otherValue1 = "test1".getBytes(); + final var value1 = "test".getBytes(); + final var otherValue1 = "test1".getBytes(); - LeafNode leafNode1 = ImmutableNodes.leafNode(LEAF_QNAME, value1); - LeafNode otherLeafNode1 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue1); + final var leafNode1 = ImmutableNodes.leafNode(LEAF_QNAME, value1); + final var otherLeafNode1 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue1); - assertFalse(leafNode1.equals(otherLeafNode1)); - assertFalse(otherLeafNode1.equals(leafNode1)); + assertNotEquals(leafNode1, otherLeafNode1); + assertNotEquals(otherLeafNode1, leafNode1); - TestValue[] value2 = new TestValue[] { new TestValue(1), new TestValue(1) }; - TestValue[] otherValue2 = new TestValue[] { new TestValue(1), new TestValue(2) }; + final var value2 = new TestValue[] { new TestValue(1), new TestValue(1) }; + final var otherValue2 = new TestValue[] { new TestValue(1), new TestValue(2) }; - LeafNode leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2); - LeafNode otherLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue2); + final var leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2); + final var otherLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue2); - assertFalse(leafNode2.equals(otherLeafNode2)); - assertFalse(otherLeafNode2.equals(leafNode2)); + assertNotEquals(leafNode2, otherLeafNode2); + assertNotEquals(otherLeafNode2, leafNode2); - byte[][] value3 = new byte[][] { "test".getBytes(), "test2".getBytes() }; - byte[][] otherValue3 = new byte[][] { "test".getBytes(), "test3".getBytes() }; + final var value3 = new byte[][] { "test".getBytes(), "test2".getBytes() }; + final var otherValue3 = new byte[][] { "test".getBytes(), "test3".getBytes() }; - LeafNode leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3); - LeafNode otherLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue3); + final var leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3); + final var otherLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue3); - assertFalse(leafNode3.equals(otherLeafNode3)); - assertFalse(otherLeafNode3.equals(leafNode3)); + assertNotEquals(leafNode3, otherLeafNode3); + assertNotEquals(otherLeafNode3, leafNode3); - TestValue[][] value4 = new TestValue[][] { + final var value4 = new TestValue[][] { new TestValue[] { new TestValue(1), new TestValue(2) }, new TestValue[] { new TestValue(3), new TestValue(4) }, }; - TestValue[][] otherValue4 = new TestValue[][] { + final var otherValue4 = new TestValue[][] { new TestValue[] { new TestValue(1), new TestValue(2) }, new TestValue[] { new TestValue(3), new TestValue(5) }, }; - LeafNode leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME, value4); - LeafNode otherLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue4); + final var leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME, value4); + final var otherLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue4); - assertFalse(leafNode4.equals(otherLeafNode4)); - assertFalse(otherLeafNode4.equals(leafNode4)); + assertNotEquals(leafNode4, otherLeafNode4); + assertNotEquals(otherLeafNode4, leafNode4); - TestValue value6 = new TestValue(1); - TestValue otherValue6 = new TestValue(2); + final var value6 = new TestValue(1); + final var otherValue6 = new TestValue(2); - LeafNode leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6); - LeafNode otherLeafNode6 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue6); + final var leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6); + final var otherLeafNode6 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue6); - assertFalse(leafNode6.equals(otherLeafNode6)); - assertFalse(otherLeafNode6.equals(leafNode6)); + assertNotEquals(leafNode6, otherLeafNode6); + assertNotEquals(otherLeafNode6, leafNode6); - String value5 = "test"; - String otherValue5 = "test2"; + final var value5 = "test"; + final var otherValue5 = "test2"; - LeafNode leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5); - LeafNode otherLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue5); + final var leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5); + final var otherLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, otherValue5); - assertFalse(leafNode5.equals(otherLeafNode5)); - assertFalse(otherLeafNode5.equals(leafNode5)); - assertFalse(leafNode5.equals(leafNode)); - assertFalse(leafNode5.equals(leafNode1)); - assertFalse(leafNode5.equals(leafNode2)); - assertFalse(leafNode5.equals(leafNode3)); - assertFalse(leafNode5.equals(leafNode4)); - assertFalse(leafNode5.equals(leafNode6)); - assertFalse(leafNode.equals(leafNode5)); - assertFalse(leafNode1.equals(leafNode5)); - assertFalse(leafNode2.equals(leafNode5)); - assertFalse(leafNode3.equals(leafNode5)); - assertFalse(leafNode4.equals(leafNode5)); - assertFalse(leafNode6.equals(leafNode5)); + assertNotEquals(leafNode5, otherLeafNode5); + assertNotEquals(otherLeafNode5, leafNode5); + assertNotEquals(leafNode5, leafNode); + assertNotEquals(leafNode5, leafNode1); + assertNotEquals(leafNode5, leafNode2); + assertNotEquals(leafNode5, leafNode3); + assertNotEquals(leafNode5, leafNode4); + assertNotEquals(leafNode5, leafNode6); + assertNotEquals(leafNode, leafNode5); + assertNotEquals(leafNode1, leafNode5); + assertNotEquals(leafNode2, leafNode5); + assertNotEquals(leafNode3, leafNode5); + assertNotEquals(leafNode4, leafNode5); + assertNotEquals(leafNode6, leafNode5); - byte[] byteValue = new byte[] { 1, 1 }; + final var byteValue = new byte[] { 1, 1 }; - LeafNode byteLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, byteValue); - assertFalse(byteLeafNode.equals(leafNode2)); - assertFalse(leafNode2.equals(byteLeafNode)); + final var byteLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, byteValue); + assertNotEquals(byteLeafNode, leafNode2); + assertNotEquals(leafNode2, byteLeafNode); } @Test // We're testing equals() @SuppressWarnings({"EqualsWithItself", "EqualsBetweenInconvertibleTypes"}) - public void equalsOtherTypesTest() { + void equalsOtherTypesTest() { - char[] valueChar = "test".toCharArray(); - char[] equalValueChar = "test".toCharArray(); + final var valueChar = "test".toCharArray(); + final var equalValueChar = "test".toCharArray(); - LeafNode leafNodeChar = ImmutableNodes.leafNode(LEAF_QNAME, valueChar); - LeafNode equalLeafNodeChar = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValueChar); + final var leafNodeChar = ImmutableNodes.leafNode(LEAF_QNAME, valueChar); + final var equalLeafNodeChar = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValueChar); - assertTrue(leafNodeChar.equals(leafNodeChar)); - assertTrue(leafNodeChar.equals(equalLeafNodeChar)); - assertTrue(equalLeafNodeChar.equals(leafNodeChar)); + assertEquals(leafNodeChar, leafNodeChar); + assertEquals(leafNodeChar, equalLeafNodeChar); + assertEquals(equalLeafNodeChar, leafNodeChar); - boolean[] value = new boolean[] { true, false }; - boolean[] equalValue = new boolean[] { true, false }; + final var value = new boolean[] { true, false }; + final var equalValue = new boolean[] { true, false }; - LeafNode leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value); - LeafNode equalLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue); + final var leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value); + final var equalLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue); - assertTrue(leafNode.equals(leafNode)); - assertTrue(leafNode.equals(equalLeafNode)); - assertTrue(equalLeafNode.equals(leafNode)); + assertEquals(leafNode, leafNode); + assertEquals(leafNode, equalLeafNode); + assertEquals(equalLeafNode, leafNode); - int[] value2 = new int[] { 1, 2 }; - int[] equalValue2 = new int[] { 1, 2 }; + final var value2 = new int[] { 1, 2 }; + final var equalValue2 = new int[] { 1, 2 }; - LeafNode leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2); - LeafNode equalLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue2); + final var leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2); + final var equalLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue2); - assertTrue(leafNode2.equals(leafNode2)); - assertTrue(leafNode2.equals(equalLeafNode2)); - assertTrue(equalLeafNode2.equals(leafNode2)); + assertEquals(leafNode2, leafNode2); + assertEquals(leafNode2, equalLeafNode2); + assertEquals(equalLeafNode2, leafNode2); - short[] value3 = new short[] { 1, 2 }; - short[] equalValue3 = new short[] { 1, 2 }; + final var value3 = new short[] { 1, 2 }; + final var equalValue3 = new short[] { 1, 2 }; - LeafNode leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3); - LeafNode equalLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue3); + final var leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3); + final var equalLeafNode3 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue3); - assertTrue(leafNode3.equals(leafNode3)); - assertTrue(leafNode3.equals(equalLeafNode3)); - assertTrue(equalLeafNode3.equals(leafNode3)); + assertEquals(leafNode3, leafNode3); + assertEquals(leafNode3, equalLeafNode3); + assertEquals(equalLeafNode3, leafNode3); - long[] value4 = new long[] { 1, 2 }; - long[] equalValue4 = new long[] { 1, 2 }; + final var value4 = new long[] { 1, 2 }; + final var equalValue4 = new long[] { 1, 2 }; - LeafNode leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME, value4); - LeafNode equalLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue4); + final var leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME, value4); + final var equalLeafNode4 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue4); - assertTrue(leafNode4.equals(leafNode4)); - assertTrue(leafNode4.equals(equalLeafNode4)); - assertTrue(equalLeafNode4.equals(leafNode4)); + assertEquals(leafNode4, leafNode4); + assertEquals(leafNode4, equalLeafNode4); + assertEquals(equalLeafNode4, leafNode4); - double[] value6 = new double[] { 1, 2 }; - double[] equalValue6 = new double[] { 1, 2 }; + final var value6 = new double[] { 1, 2 }; + final var equalValue6 = new double[] { 1, 2 }; - LeafNode leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6); - LeafNode equalLeafNode6 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue6); + final var leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6); + final var equalLeafNode6 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue6); - assertTrue(leafNode6.equals(leafNode6)); - assertTrue(leafNode6.equals(equalLeafNode6)); - assertTrue(equalLeafNode6.equals(leafNode6)); + assertEquals(leafNode6, leafNode6); + assertEquals(leafNode6, equalLeafNode6); + assertEquals(equalLeafNode6, leafNode6); - float[] value5 = new float[] { 1, 2 }; - float[] equalValue5 = new float[] { 1, 2 }; + final var value5 = new float[] { 1, 2 }; + final var equalValue5 = new float[] { 1, 2 }; - LeafNode leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5); - LeafNode equalLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue5); + final var leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5); + final var equalLeafNode5 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue5); - assertTrue(leafNode5.equals(leafNode5)); - assertTrue(leafNode5.equals(equalLeafNode5)); - assertTrue(equalLeafNode5.equals(leafNode5)); + assertEquals(leafNode5, leafNode5); + assertEquals(leafNode5, equalLeafNode5); + assertEquals(equalLeafNode5, leafNode5); - assertFalse(leafNode.equals(leafNode5)); - assertFalse(leafNode2.equals(leafNode5)); - assertFalse(leafNode3.equals(leafNode5)); - assertFalse(leafNode4.equals(leafNode5)); - assertFalse(leafNodeChar.equals(leafNode5)); - assertFalse(leafNode6.equals(leafNode5)); + assertNotEquals(leafNode, leafNode5); + assertNotEquals(leafNode2, leafNode5); + assertNotEquals(leafNode3, leafNode5); + assertNotEquals(leafNode4, leafNode5); + assertNotEquals(leafNodeChar, leafNode5); + assertNotEquals(leafNode6, leafNode5); - assertFalse(leafNode5.equals(leafNode)); - assertFalse(leafNode5.equals(leafNode2)); - assertFalse(leafNode5.equals(leafNode3)); - assertFalse(leafNode5.equals(leafNode4)); - assertFalse(leafNode5.equals(leafNodeChar)); - assertFalse(leafNode5.equals(leafNode6)); + assertNotEquals(leafNode5, leafNode); + assertNotEquals(leafNode5, leafNode2); + assertNotEquals(leafNode5, leafNode3); + assertNotEquals(leafNode5, leafNode4); + assertNotEquals(leafNode5, leafNodeChar); + assertNotEquals(leafNode5, leafNode6); } } diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/YT1417Test.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/YT1417Test.java index 3d69a57b9f..8d7d23a480 100644 --- a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/YT1417Test.java +++ b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/YT1417Test.java @@ -7,15 +7,15 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema.nodes; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; @@ -25,13 +25,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -@RunWith(MockitoJUnitRunner.StrictStubs.class) -public class YT1417Test { +@ExtendWith(MockitoExtension.class) +class YT1417Test { public static final QName FOO = QName.create("foo", "foo"); public static final QName BAR = QName.create("foo", "bar"); @Test - public void testContainerNodeEquality() { + void testContainerNodeEquality() { final var mock = mock(ContainerNode.class); doReturn(new NodeIdentifier(FOO)).when(mock).name(); doReturn(1).when(mock).size(); @@ -63,7 +63,7 @@ public class YT1417Test { } @Test - public void testSystemLeafSetNodeEquality() { + void testSystemLeafSetNodeEquality() { final var mock = mock(SystemLeafSetNode.class); doReturn(new NodeIdentifier(FOO)).when(mock).name(); doReturn(1).when(mock).size(); @@ -113,7 +113,7 @@ public class YT1417Test { } @Test - public void testUserLeafSetNodeEquality() { + void testUserLeafSetNodeEquality() { final var mock = mock(UserLeafSetNode.class); doReturn(new NodeIdentifier(FOO)).when(mock).name(); doReturn(List.of( -- 2.36.6