2 * Copyright (c) 2014 Brocade Communications 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.test.codecs;
11 import static org.junit.Assert.*;
12 import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
13 import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.data.api.codec.Uint8Codec;
17 import org.opendaylight.yangtools.yang.model.util.Uint8;
20 * Unit tests for Uint8CodecString.
22 * @author Thomas Pantelis
24 public class Uint8CodecStringTest {
26 @SuppressWarnings({ "unchecked" })
28 public void testSerialize() {
29 Uint8Codec<String> codec = getCodec(Uint8.getInstance(), Uint8Codec.class);
31 assertEquals("serialize", "10", codec.serialize(Short.valueOf((short) 10 )));
32 assertEquals("serialize", "", codec.serialize(null));
35 @SuppressWarnings({ "unchecked" })
37 public void testDererialize() {
38 final String hexa = "0x40";
39 final String octal = "0100";
40 final String integer = "64";
42 Uint8Codec<String> codec = getCodec(Uint8.getInstance(), Uint8Codec.class);
44 assertEquals("deserialize", codec.deserialize(hexa), Short.valueOf("040", 16));
45 assertEquals("deserialize", codec.deserialize(octal), Short.valueOf(octal, 8));
46 assertEquals("deserialize", codec.deserialize(integer), Short.valueOf(integer, 10));
47 assertEquals("deserialize", codec.deserialize("0"), Short.valueOf("0", 10));
49 deserializeWithExpectedIllegalArgEx(codec, "1o");
50 deserializeWithExpectedIllegalArgEx(codec, "");
51 deserializeWithExpectedIllegalArgEx(codec, null);