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.Uint8;
16 import org.opendaylight.yangtools.yang.data.api.codec.Uint8Codec;
17 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
20 * Unit tests for Uint8CodecString.
22 * @author Thomas Pantelis
24 public class Uint8CodecStringTest {
25 @SuppressWarnings({ "unchecked" })
27 public void testSerialize() {
28 Uint8Codec<String> codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class);
29 assertEquals("10", codec.serialize(Uint8.valueOf((short) 10)));
32 @SuppressWarnings({ "unchecked" })
34 public void testDererialize() {
35 final String hexa = "0x40";
36 final String octal = "0100";
37 final String integer = "64";
39 Uint8Codec<String> codec = getCodec(BaseTypes.uint8Type(), Uint8Codec.class);
41 assertEquals(Uint8.valueOf("040", 16), codec.deserialize(hexa));
42 assertEquals(Uint8.valueOf(octal, 8), codec.deserialize(octal));
43 assertEquals(Uint8.valueOf(integer, 10), codec.deserialize(integer));
44 assertEquals(Uint8.valueOf("0", 10), codec.deserialize("0"));
46 deserializeWithExpectedIllegalArgEx(codec, "1o");
47 deserializeWithExpectedIllegalArgEx(codec, "");