Fix odlparent-3-detected checkstyle issues
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codecs / Uint64CodecStringTest.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.assertEquals;
12
13 import java.math.BigInteger;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.data.api.codec.Uint64Codec;
16 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
17
18 /**
19  * Unit tests for Uint64CodecString.
20  *
21  * @author Thomas Pantelis
22  */
23 public class Uint64CodecStringTest {
24
25     @SuppressWarnings("unchecked")
26     @Test
27     public void testSerialize() {
28         Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(),
29             Uint64Codec.class);
30
31         assertEquals("serialize", "123456789", codec.serialize(BigInteger.valueOf(123456789)));
32         assertEquals("serialize", "", codec.serialize(null));
33     }
34
35     @SuppressWarnings("unchecked")
36     @Test
37     public void testDeserialize() {
38         final String hexa = "0X75EDC78edCBA";
39         final String octal = "03536670743556272";
40         final String integer = "129664115727546";
41
42         Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(),
43             Uint64Codec.class);
44
45         assertEquals("deserialize", codec.deserialize(hexa), new BigInteger("75EDC78edCBA", 16));
46         assertEquals("deserialize", codec.deserialize(octal), new BigInteger(octal, 8));
47         assertEquals("deserialize", codec.deserialize(integer), new BigInteger(integer, 10));
48
49         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "12345o");
50         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
51         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, null);
52     }
53 }