Migrate yang-data-impl to JUnit5
[yangtools.git] / data / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codec / Int32CodecStringTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.impl.codec;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11
12 import org.junit.jupiter.api.Test;
13 import org.opendaylight.yangtools.yang.data.api.codec.Int32Codec;
14 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
15
16 /**
17  * Unit tests for Int32CodecString.
18  *
19  * @author Thomas Pantelis
20  */
21 class Int32CodecStringTest {
22     @SuppressWarnings("unchecked")
23     @Test
24     void testSerialize() {
25         final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class);
26         assertEquals("10", codec.serialize(Integer.valueOf(10)), "serialize");
27     }
28
29     @SuppressWarnings("unchecked")
30     @Test
31     void testDeserialize() {
32         final var hexa = "0x45FFFCDE";
33         final var negHexa = "-0x45FFFCDE";
34         final var octal = "010577776336";
35         final var negOctal = "-010577776336";
36         final var integer = "1174404318";
37         final var negInteger = "-1174404318";
38
39         final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int32Type(), Int32Codec.class);
40
41         assertEquals(codec.deserialize(hexa), Integer.valueOf("+045FFFCDE", 16), "deserialize");
42         assertEquals(codec.deserialize(negHexa), Integer.valueOf("-045FFFCDE", 16), "deserialize");
43         assertEquals(codec.deserialize(octal), Integer.valueOf(octal, 8), "deserialize");
44         assertEquals(codec.deserialize(negOctal), Integer.valueOf(negOctal, 8), "deserialize");
45         assertEquals(codec.deserialize(integer), Integer.valueOf(integer, 10), "deserialize");
46         assertEquals(codec.deserialize(negInteger), Integer.valueOf(negInteger, 10), "deserialize");
47
48         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o");
49         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
50     }
51 }