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;
14 import org.opendaylight.yangtools.yang.data.api.codec.EnumCodec;
15 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
16 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
17 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition;
20 * Unit tests for EnumCodecString.
22 * @author Thomas Pantelis
24 public class EnumCodecStringTest {
26 @SuppressWarnings("unchecked")
28 public void testSerialize() {
29 EnumCodec<String> codec = getCodec( toEnumTypeDefinition( "enum1", "enum2" ), EnumCodec.class);
31 assertEquals( "serialize", "enum1", codec.serialize( "enum1" ) );
32 assertEquals( "serialize", "", codec.serialize( null ) );
35 @SuppressWarnings("unchecked")
37 public void testDeserialize() {
38 EnumCodec<String> codec = getCodec( toEnumTypeDefinition( "enum1", "enum2" ), EnumCodec.class);
40 assertEquals( "deserialize", "enum1", codec.deserialize( "enum1" ) );
41 assertEquals( "deserialize", "enum2", codec.deserialize( "enum2" ) );
43 deserializeWithExpectedIllegalArgEx( codec, "enum3" );