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.Int32Codec;
15 import org.opendaylight.yangtools.yang.model.util.Int32;
18 * Unit tests for Int32CodecString.
20 * @author Thomas Pantelis
22 public class Int32CodecStringTest {
24 @SuppressWarnings("unchecked")
26 public void testSerialize() {
27 Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int32.getInstance(), Int32Codec.class);
29 assertEquals("serialize", "10", codec.serialize(Integer.valueOf( 10 )));
30 assertEquals("serialize", "", codec.serialize(null));
33 @SuppressWarnings("unchecked")
35 public void testDeserialize() {
36 final String hexa = "0x45FFFCDE";
37 final String negHexa = "-0x45FFFCDE";
38 final String octal = "010577776336";
39 final String negOctal = "-010577776336";
40 final String integer = "1174404318";
41 final String negInteger = "-1174404318";
43 Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int32.getInstance(), Int32Codec.class);
45 assertEquals("deserialize", codec.deserialize(hexa), Integer.valueOf("+045FFFCDE", 16));
46 assertEquals("deserialize", codec.deserialize(negHexa), Integer.valueOf("-045FFFCDE", 16));
47 assertEquals("deserialize", codec.deserialize(octal), Integer.valueOf(octal, 8));
48 assertEquals("deserialize", codec.deserialize(negOctal), Integer.valueOf(negOctal, 8));
49 assertEquals("deserialize", codec.deserialize(integer), Integer.valueOf(integer, 10));
50 assertEquals("deserialize", codec.deserialize(negInteger), Integer.valueOf(negInteger, 10));
52 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o");
53 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
54 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, null);