Bug 5085: Clean-up test and retest JUnit tests
[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.*;
12
13 import org.junit.Test;
14
15 import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec;
16 import org.opendaylight.yangtools.yang.model.util.BooleanType;
17
18 /**
19  * Unit tests for BooleanCodecString.
20  *
21  * @author Thomas Pantelis
22  */
23 public class BooleanCodecStringTest {
24
25     @SuppressWarnings("unchecked")
26     @Test
27     public void testSerialize() {
28         BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( BooleanType.getInstance(), BooleanCodec.class);
29
30         assertEquals( "serialize", "", codec.serialize( null ) );
31         assertEquals( "serialize", "true", codec.serialize( true ) );
32         assertEquals( "serialize", "false", codec.serialize( false ) );
33     }
34
35     @SuppressWarnings("unchecked")
36     @Test
37     public void testDeserialize() {
38         BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( BooleanType.getInstance(), BooleanCodec.class);
39
40         assertEquals( "deserialize", Boolean.TRUE, codec.deserialize( "true" ) );
41         assertEquals( "deserialize", Boolean.TRUE, codec.deserialize( "TRUE" ) );
42         assertEquals( "deserialize", Boolean.FALSE, codec.deserialize( "FALSE" ) );
43         assertEquals( "deserialize", Boolean.FALSE, codec.deserialize( "false" ) );
44         assertEquals( "deserialize", null, codec.deserialize( null ) );
45         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo");
46         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");
47     }
48 }