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.*;
12 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
13 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.data.api.codec.Int16Codec;
17 import org.opendaylight.yangtools.yang.model.util.Int16;
20 * Unit tests for Int8CodecString.
22 * @author Thomas Pantelis
24 public class Int16CodecStringTest {
26 @SuppressWarnings("unchecked")
28 public void testSerialize() {
29 Int16Codec<String> codec = getCodec(Int16.getInstance(), Int16Codec.class);
31 assertEquals("serialize", "10", codec.serialize(Short.valueOf( (short) 10 )));
32 assertEquals("serialize", "", codec.serialize(null));
35 @SuppressWarnings("unchecked")
37 public void testDeserialize() {
38 final String hexa = "+0X45c";
39 final String negHexa = "-0X45c";
40 final String octal = "02134";
41 final String negOctal = "-02134";
42 final String integer = "+1116";
43 final String negInteger = "-1116";
45 Int16Codec<String> codec = getCodec(Int16.getInstance(), Int16Codec.class);
47 assertEquals("deserialize", codec.deserialize(hexa), Short.valueOf("+045c", 16));
48 assertEquals("deserialize", codec.deserialize(negHexa), Short.valueOf("-045c", 16));
49 assertEquals("deserialize", codec.deserialize(octal), Short.valueOf(octal, 8));
50 assertEquals("deserialize", codec.deserialize(negOctal), Short.valueOf(negOctal, 8));
51 assertEquals("deserialize", codec.deserialize(integer), Short.valueOf(integer, 10));
52 assertEquals("deserialize", codec.deserialize(negInteger), Short.valueOf(negInteger, 10));
54 deserializeWithExpectedIllegalArgEx(codec, "1o");
55 deserializeWithExpectedIllegalArgEx(codec, "");
56 deserializeWithExpectedIllegalArgEx(codec, null);