Migrate yang-data-impl to JUnit5
[yangtools.git] / data / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codec / Uint16CodecStringTest.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 import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
12 import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec;
13
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.common.Uint16;
16 import org.opendaylight.yangtools.yang.data.api.codec.Uint16Codec;
17 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
18
19 /**
20  * Unit tests for Uint16CodecString.
21  *
22  * @author Thomas Pantelis
23  */
24 class Uint16CodecStringTest {
25     @SuppressWarnings("unchecked")
26     @Test
27     void testSerialize() {
28         final var codec = getCodec(BaseTypes.uint16Type(), Uint16Codec.class);
29         assertEquals("10", codec.serialize(Uint16.valueOf(10)));
30     }
31
32     @SuppressWarnings("unchecked")
33     @Test
34     void testDeserialize() {
35         final var hexa = "0X45c";
36         final var octal = "02134";
37         final var integer = "1116";
38
39         final var codec = getCodec(BaseTypes.uint16Type(), Uint16Codec.class);
40
41         assertEquals(Uint16.valueOf("045c", 16), codec.deserialize(hexa));
42         assertEquals(Uint16.valueOf(octal, 8), codec.deserialize(octal));
43         assertEquals(Uint16.valueOf(integer, 10), codec.deserialize(integer));
44
45         deserializeWithExpectedIllegalArgEx(codec, "1o");
46         deserializeWithExpectedIllegalArgEx(codec, "");
47     }
48 }