Do not pretty-print body class
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codec / Int8CodecStringTest.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 package org.opendaylight.yangtools.yang.data.impl.codec;
9
10 import static org.junit.Assert.assertEquals;
11
12 import org.junit.Test;
13 import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec;
14 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
15
16 /**
17  * Unit tests for Int8CodecString.
18  *
19  * @author Thomas Pantelis
20  */
21 public class Int8CodecStringTest {
22     @SuppressWarnings("unchecked")
23     @Test
24     public void testSerialize() {
25         Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class);
26
27         assertEquals("serialize", "10", codec.serialize(Byte.valueOf((byte) 10)));
28     }
29
30     @SuppressWarnings("unchecked")
31     @Test
32     public void testDeserialize() {
33         final String hexa = "0x40";
34         final String negHexa = "-0x40";
35         final String octal = "+0100";
36         final String negOctal = "-0100";
37         final String integer = "64";
38         final String negInteger = "-64";
39
40         Int8Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.int8Type(), Int8Codec.class);
41
42         assertEquals("deserialize", codec.deserialize(hexa), Byte.valueOf("040", 16));
43         assertEquals("deserialize", codec.deserialize(negHexa), Byte.valueOf("-040", 16));
44         assertEquals("deserialize", codec.deserialize(octal), Byte.valueOf(octal, 8));
45         assertEquals("deserialize", codec.deserialize(negOctal), Byte.valueOf(negOctal, 8));
46         assertEquals("deserialize", codec.deserialize(integer), Byte.valueOf(integer, 10));
47         assertEquals("deserialize", codec.deserialize(negInteger), Byte.valueOf(negInteger, 10));
48
49         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o");
50         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
51     }
52 }