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
9 package org.opendaylight.yangtools.yang.data.impl.codecs;
11 import static org.junit.Assert.*;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec;
15 import org.opendaylight.yangtools.yang.model.util.Int8;
18 * Unit tests for Int8CodecString.
20 * @author Thomas Pantelis
22 public class Int8CodecStringTest {
24 @SuppressWarnings("unchecked")
26 public void testSerialize() {
27 Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int8.getInstance(), Int8Codec.class);
29 assertEquals("serialize", "10", codec.serialize(Byte.valueOf( (byte) 10 )));
30 assertEquals("serialize", "", codec.serialize(null));
33 @SuppressWarnings("unchecked")
35 public void testDeserialize() {
36 final String hexa = "0x40";
37 final String negHexa = "-0x40";
38 final String octal = "+0100";
39 final String negOctal = "-0100";
40 final String integer = "64";
41 final String negInteger = "-64";
43 Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int8.getInstance(), Int8Codec.class);
45 assertEquals("deserialize", codec.deserialize(hexa), Byte.valueOf("040", 16));
46 assertEquals("deserialize", codec.deserialize(negHexa), Byte.valueOf("-040", 16));
47 assertEquals("deserialize", codec.deserialize(octal), Byte.valueOf(octal, 8));
48 assertEquals("deserialize", codec.deserialize(negOctal), Byte.valueOf(negOctal, 8));
49 assertEquals("deserialize", codec.deserialize(integer), Byte.valueOf(integer, 10));
50 assertEquals("deserialize", codec.deserialize(negInteger), Byte.valueOf(negInteger, 10));
52 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o");
53 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
54 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, null);