*/
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;
*
* @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<String> 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<String> codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class);
+ void testDererialize() {
+ @SuppressWarnings("unchecked")
+ final var codec = (BinaryCodec<String>)
+ TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.binaryType(), BinaryCodec.class);
assertArrayEquals(FOUR_ELEMENTS, codec.deserialize(Base64.getEncoder().encodeToString(FOUR_ELEMENTS)));
}
}
*/
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);
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- BitsCodec<String> 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<String>) 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<String> 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");
}
*/
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;
*
* @author Thomas Pantelis
*/
-public class BooleanCodecStringTest {
+class BooleanCodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- BooleanCodec<String> 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<String> 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");
*/
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;
*
* @author Thomas Pantelis
*/
-public class DecimalCodecStringTest {
+class DecimalCodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- DecimalCodec<String> 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<String> 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"));
*/
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;
*
* @author Thomas Pantelis
*/
-public class EmptyCodecStringTest {
-
+class EmptyCodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- EmptyCodec<String> 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<String> 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");
}
*/
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;
/**
*
* @author Thomas Pantelis
*/
-public class EnumCodecStringTest {
+class EnumCodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- EnumCodec<String> 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<String> 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");
}
*/
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;
*
* @author Thomas Pantelis
*/
-public class Int16CodecStringTest {
+class Int16CodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- Int16Codec<String> 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<String> 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, "");
*/
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;
*
* @author Thomas Pantelis
*/
-public class Int32CodecStringTest {
+class Int32CodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- Int32Codec<String> 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<String> 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, "");
*/
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;
*
* @author Thomas Pantelis
*/
-public class Int64CodecStringTest {
-
+class Int64CodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- Int64Codec<String> 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<String> 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, "");
*/
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;
*
* @author Thomas Pantelis
*/
-public class Int8CodecStringTest {
+class Int8CodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- Int8Codec<String> 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<String> 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, "");
*/
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<String> 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<String> 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<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(type, StringCodec.class);
+ final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(type, StringCodec.class);
assertEquals("🌞", codec.deserialize("🌞"));
}
*/
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;
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";
*/
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;
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> T getCodec(final TypeDefinition<?> def, final Class<T> clazz) {
- TypeDefinitionAwareCodec<?, ?> codec = TypeDefinitionAwareCodec.fromType(def);
- assertThat(codec, instanceOf(clazz));
+ static <T> T getCodec(final TypeDefinition<?> def, final Class<T> clazz) {
+ final var codec = TypeDefinitionAwareCodec.fromType(def);
+ assertInstanceOf(clazz, codec);
return clazz.cast(codec);
}
- public static void deserializeWithExpectedIllegalArgEx(final IllegalArgumentCodec<String, ?> codec,
+ static void deserializeWithExpectedIllegalArgEx(final IllegalArgumentCodec<String, ?> 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);
*/
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;
*
* @author Thomas Pantelis
*/
-public class Uint16CodecStringTest {
+class Uint16CodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- Uint16Codec<String> 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<String> 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));
*/
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;
*
* @author Thomas Pantelis
*/
-public class Uint32CodecStringTest {
+class Uint32CodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- Uint32Codec<String> 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<String> 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));
*/
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;
*
* @author Thomas Pantelis
*/
-public class Uint64CodecStringTest {
+class Uint64CodecStringTest {
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- Uint64Codec<String> 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<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(),
+ final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(),
Uint64Codec.class);
assertEquals(Uint64.valueOf("75EDC78edCBA", 16), codec.deserialize(hexa));
*/
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;
*
* @author Thomas Pantelis
*/
-public class Uint8CodecStringTest {
- @SuppressWarnings({ "unchecked" })
+class Uint8CodecStringTest {
+ @SuppressWarnings({"unchecked"})
@Test
- public void testSerialize() {
- Uint8Codec<String> 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<String> 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));
*/
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);
}
@SuppressWarnings("unchecked")
@Test
- public void testSerialize() {
- UnionCodec<String> 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<String> 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");
*/
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;
}
}
}""").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");
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)));
}
}
*/
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;
}
}""").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));
}
}
*/
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;
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;
}
}""")
.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());
}
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;
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");
private static final int SIZE = 3;
private static final NodeWithValue<String> BAR_PATH = new NodeWithValue<>(LEAF_LIST_MAIN, "bar");
private static final LeafSetEntryNode<String> LEAF_SET_ENTRY_NODE =
- ImmutableLeafSetEntryNodeBuilder.<String>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.<String>create().withNodeIdentifier(BAR_PATH).withValue("bar").build();
@Test
- public void immutableOrderedMapBuilderTest() {
- final var mapEntryNodeColl = new LinkedList<MapEntryNode>();
- mapEntryNodeColl.add(LIST_MAIN_CHILD_3);
- final var keys = new HashMap<QName, Object>();
- 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();
}
@Test
- public void immutableUserLeafSetNodeBuilderTest() {
- final UserLeafSetNode<String> orderedLeafSet = ImmutableUserLeafSetNodeBuilder.<String>create()
+ void immutableUserLeafSetNodeBuilderTest() {
+ final var orderedLeafSet = ImmutableUserLeafSetNodeBuilder.<String>create()
.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
.withChild(LEAF_SET_ENTRY_NODE)
.withChildValue("baz")
.removeChild(BAR_PATH)
.build();
- final LinkedList<LeafSetNode<?>> 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<MapEntryNode> mapEntryNodeColl = new LinkedList<>();
- mapEntryNodeColl.add(LIST_MAIN_CHILD_3);
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> 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));
}
@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<Object> 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)
*/
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;
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;
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");
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);
*/
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";
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()
}
@Test
- public void testLeafList() {
+ void testLeafList() {
assertEquals(Builders.containerBuilder()
.withNodeIdentifier(rootContainer)
.withChild(Builders.orderedLeafSetBuilder()
}
@Test
- public void testEmptyInstanceIdentifier() {
+ void testEmptyInstanceIdentifier() {
assertEquals(ImmutableNodes.containerNode(SchemaContext.NAME),
ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.of()));
}
@Test
- public void testKeyOrdering() {
+ void testKeyOrdering() {
final Map<QName, Object> 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<MapEntryNode> 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());
*/
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<NodeIdentifier, ContainerNode> builder = Builders
- .containerBuilder().withNodeIdentifier(getNodeIdentifier("container"));
-
- // leaf
- LeafNode<String> leafChild = Builders.<String>leafBuilder().withNodeIdentifier(getNodeIdentifier("leaf"))
- .withValue("String").build();
- builder.withChild(leafChild);
-
- // leafList
- LeafSetNode<Integer> leafList = Builders.<Integer>leafSetBuilder()
+ final var builder = Builders.containerBuilder()
+ .withNodeIdentifier(getNodeIdentifier("container"))
+ .withChild(Builders.<String>leafBuilder()
+ .withNodeIdentifier(getNodeIdentifier("leaf"))
+ .withValue("String")
+ .build())
+ .withChild(Builders.<Integer>leafSetBuilder()
.withNodeIdentifier(getNodeIdentifier("leaf"))
.withChildValue(1)
.withChild(Builders.<Integer>leafSetEntryBuilder()
- .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
- .build();
- builder.withChild(leafList);
-
- // list
- MapEntryNode listChild1 = Builders
- .mapEntryBuilder()
- .withChild(
- Builders.<Integer>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.<Integer>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.<Integer>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.<Integer>leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
- .withValue(11).build());
+ // This works without schema (adding child from augment as a direct child)
+ builder.withChild(Builders.<Integer>leafBuilder()
+ .withNodeIdentifier(getNodeIdentifier("augmentUint32"))
+ .withValue(11)
+ .build());
}
private static <T> NodeWithValue<T> getNodeWithValueIdentifier(final String localName, final T value) {
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;
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");
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.
* @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<NormalizedNode> listFooResult = NormalizedNodes.findNode(tree, LIST_A_FOO_PATH);
+ final var listFooResult = NormalizedNodes.findNode(tree, LIST_A_FOO_PATH);
assertTrue(listFooResult.isPresent());
- Optional<NormalizedNode> listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH);
+ final var listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH);
assertTrue(listTwoResult.isPresent());
}
}
*/
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"))
.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"))
.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"))
.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"))
.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"))
.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"))
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());
}
}
*/
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
}
@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<byte[]> leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value);
- LeafNode<byte[]> 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<TestValue[]> leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2);
- LeafNode<TestValue[]> 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<byte[][]> leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME,
+ final var leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME,
value3);
- LeafNode<byte[][]> 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<TestValue[][]> leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME,value4);
- LeafNode<TestValue[][]> 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<TestValue> leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6);
- LeafNode<TestValue> 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<String> leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5);
- LeafNode<String> 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<byte[]> leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value);
- LeafNode<byte[]> 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<byte[]> leafNode1 = ImmutableNodes.leafNode(LEAF_QNAME, value1);
- LeafNode<byte[]> 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<TestValue[]> leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2);
- LeafNode<TestValue[]> 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<byte[][]> leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3);
- LeafNode<byte[][]> 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<TestValue[][]> leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME, value4);
- LeafNode<TestValue[][]> 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<TestValue> leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6);
- LeafNode<TestValue> 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<String> leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5);
- LeafNode<String> 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<byte[]> 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<char[]> leafNodeChar = ImmutableNodes.leafNode(LEAF_QNAME, valueChar);
- LeafNode<char[]> 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<boolean[]> leafNode = ImmutableNodes.leafNode(LEAF_QNAME, value);
- LeafNode<boolean[]> 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<int[]> leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2);
- LeafNode<int[]> 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<short[]> leafNode3 = ImmutableNodes.leafNode(LEAF_QNAME, value3);
- LeafNode<short[]> 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<long[]> leafNode4 = ImmutableNodes.leafNode(LEAF_QNAME, value4);
- LeafNode<long[]> 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<double[]> leafNode6 = ImmutableNodes.leafNode(LEAF_QNAME, value6);
- LeafNode<double[]> 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<float[]> leafNode5 = ImmutableNodes.leafNode(LEAF_QNAME, value5);
- LeafNode<float[]> 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);
}
}
*/
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;
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();
}
@Test
- public void testSystemLeafSetNodeEquality() {
+ void testSystemLeafSetNodeEquality() {
final var mock = mock(SystemLeafSetNode.class);
doReturn(new NodeIdentifier(FOO)).when(mock).name();
doReturn(1).when(mock).size();
}
@Test
- public void testUserLeafSetNodeEquality() {
+ void testUserLeafSetNodeEquality() {
final var mock = mock(UserLeafSetNode.class);
doReturn(new NodeIdentifier(FOO)).when(mock).name();
doReturn(List.of(