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.*;
12 import java.util.Collections;
13 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.data.api.codec.BitsCodec;
16 import com.google.common.collect.ImmutableSet;
19 * Unit tests for BitsCodecString.
21 * @author Thomas Pantelis
24 public class BitsCodecStringTest {
26 @SuppressWarnings("unchecked")
28 public void testSerialize() {
30 BitsCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( TypeDefinitionAwareCodecTestHelper.toBitsTypeDefinition( "foo" ), BitsCodec.class );
32 ImmutableSet<String> toSerialize = ImmutableSet.of("foo", "bar");
34 String serialized = codec.serialize(toSerialize);
35 assertNotNull(serialized);
36 assertTrue(serialized.contains("foo"));
37 assertTrue(serialized.contains("bar"));
39 assertEquals("serialize", "",
40 codec.serialize(ImmutableSet.of()));
41 assertEquals("serialize", "", codec.serialize(null));
44 @SuppressWarnings("unchecked")
46 public void testDeserialize() {
48 BitsCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec( TypeDefinitionAwareCodecTestHelper.toBitsTypeDefinition( "bit1", "bit2" ), BitsCodec.class );
50 assertEquals("deserialize", ImmutableSet.of("bit1", "bit2"), codec.deserialize(" bit1 bit2 "));
52 assertEquals("deserialize", Collections.emptySet(), codec.deserialize(""));
53 assertEquals("deserialize", Collections.emptySet(), codec.deserialize(null));
55 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "bit1 bit3");