Cleanup codecs a bit
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codecs / BooleanCodecStringTest.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 org.junit.Test;
14 import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec;
15 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
16
17 /**
18  * Unit tests for BooleanCodecString.
19  *
20  * @author Thomas Pantelis
21  */
22 public class BooleanCodecStringTest {
23
24     @SuppressWarnings("unchecked")
25     @Test
26     public void testSerialize() {
27         BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(),
28             BooleanCodec.class);
29
30         assertEquals("serialize", "", codec.serialize(null));
31         assertEquals("serialize", "true", codec.serialize(Boolean.TRUE));
32         assertEquals("serialize", "false", codec.serialize(Boolean.FALSE));
33     }
34
35     @SuppressWarnings("unchecked")
36     @Test
37     public void testDeserialize() {
38         BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(),
39             BooleanCodec.class);
40
41         assertEquals("deserialize", Boolean.TRUE, codec.deserialize("true"));
42         assertEquals("deserialize", Boolean.TRUE, codec.deserialize("TRUE"));
43         assertEquals("deserialize", Boolean.FALSE, codec.deserialize("FALSE"));
44         assertEquals("deserialize", Boolean.FALSE, codec.deserialize("false"));
45         assertEquals("deserialize", null, codec.deserialize(null));
46         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo");
47         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
48     }
49 }