2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.impl.codec;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
12 import org.junit.jupiter.api.Test;
13 import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec;
14 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
17 * Unit tests for Int8CodecString.
19 * @author Thomas Pantelis
21 class Int8CodecStringTest {
22 @SuppressWarnings("unchecked")
24 void testSerialize() {
25 final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class);
27 assertEquals("10", codec.serialize(Byte.valueOf((byte) 10)), "serialize");
30 @SuppressWarnings("unchecked")
32 void testDeserialize() {
33 final var hexa = "0x40";
34 final var negHexa = "-0x40";
35 final var octal = "+0100";
36 final var negOctal = "-0100";
37 final var integer = "64";
38 final var negInteger = "-64";
40 final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class);
42 assertEquals(codec.deserialize(hexa), Byte.valueOf("040", 16), "deserialize");
43 assertEquals(codec.deserialize(negHexa), Byte.valueOf("-040", 16), "deserialize");
44 assertEquals(codec.deserialize(octal), Byte.valueOf(octal, 8), "deserialize");
45 assertEquals(codec.deserialize(negOctal), Byte.valueOf(negOctal, 8), "deserialize");
46 assertEquals(codec.deserialize(integer), Byte.valueOf(integer, 10), "deserialize");
47 assertEquals(codec.deserialize(negInteger), Byte.valueOf(negInteger, 10), "deserialize");
49 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o");
50 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");