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.codecs;
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
12 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
14 import org.junit.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.util.type.BaseTypes;
20 * Unit tests for Uint16CodecString.
22 * @author Thomas Pantelis
24 public class Uint16CodecStringTest {
25 @SuppressWarnings("unchecked")
27 public void testSerialize() {
28 Uint16Codec<String> codec = getCodec(BaseTypes.uint16Type(), Uint16Codec.class);
29 assertEquals("10", codec.serialize(Uint16.valueOf(10)));
32 @SuppressWarnings("unchecked")
34 public void testDeserialize() {
35 final String hexa = "0X45c";
36 final String octal = "02134";
37 final String integer = "1116";
39 Uint16Codec<String> codec = getCodec(BaseTypes.uint16Type(), Uint16Codec.class);
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));
45 deserializeWithExpectedIllegalArgEx(codec, "1o");
46 deserializeWithExpectedIllegalArgEx(codec, "");