2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.yang.data.impl.codecs;
11 import static org.junit.Assert.*;
13 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec;
16 import org.opendaylight.yangtools.yang.model.util.BooleanType;
19 * Unit tests for BooleanCodecString.
21 * @author Thomas Pantelis
23 public class BooleanCodecStringTest {
25 @SuppressWarnings("unchecked")
27 public void testSerialize() {
28 BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( BooleanType.getInstance(), BooleanCodec.class);
30 assertEquals( "serialize", "", codec.serialize( null ) );
31 assertEquals( "serialize", "true", codec.serialize( true ) );
32 assertEquals( "serialize", "false", codec.serialize( false ) );
35 @SuppressWarnings("unchecked")
37 public void testDeserialize() {
38 BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( BooleanType.getInstance(), BooleanCodec.class);
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, "");