Scripted update of if statements
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codecs / Int32CodecStringTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.data.impl.codecs;
10
11 import static org.junit.Assert.*;
12
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.data.api.codec.Int32Codec;
15 import org.opendaylight.yangtools.yang.model.util.Int32;
16
17 /**
18  * Unit tests for Int32CodecString.
19  *
20  * @author Thomas Pantelis
21  */
22 public class Int32CodecStringTest {
23
24     @SuppressWarnings("unchecked")
25     @Test
26     public void testSerialize() {
27         Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int32.getInstance(), Int32Codec.class);
28
29         assertEquals("serialize", "10", codec.serialize(Integer.valueOf( 10 )));
30         assertEquals("serialize", "", codec.serialize(null));
31     }
32
33     @SuppressWarnings("unchecked")
34     @Test
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";
42
43         Int32Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int32.getInstance(), Int32Codec.class);
44
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));
51
52         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o");
53         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
54         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, null);
55     }
56 }