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.assertEquals;
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;
18 * Unit tests for BooleanCodecString.
20 * @author Thomas Pantelis
22 public class BooleanCodecStringTest {
24 @SuppressWarnings("unchecked")
26 public void testSerialize() {
27 BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(),
30 assertEquals("serialize", "", codec.serialize(null));
31 assertEquals("serialize", "true", codec.serialize(Boolean.TRUE));
32 assertEquals("serialize", "false", codec.serialize(Boolean.FALSE));
35 @SuppressWarnings("unchecked")
37 public void testDeserialize() {
38 BooleanCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.booleanType(),
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, "");