2 * Copyright (c) 2014 Brocade Communications 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.test.codecs;
11 import static org.junit.Assert.*;
12 import java.util.Collections;
13 import org.junit.Test;
15 import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
16 import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.toBitsTypeDefinition;
17 import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
19 import org.opendaylight.yangtools.yang.data.api.codec.BitsCodec;
20 import com.google.common.collect.ImmutableSet;
23 * Unit tests for BitsCodecString.
25 * @author Thomas Pantelis
28 public class BitsCodecStringTest {
30 @SuppressWarnings("unchecked")
32 public void testSerialize() {
34 BitsCodec<String> codec = getCodec( toBitsTypeDefinition( "foo" ), BitsCodec.class );
36 ImmutableSet<String> toSerialize = ImmutableSet.of("foo", "bar");
38 String serialized = codec.serialize(toSerialize);
39 assertNotNull(serialized);
40 assertTrue(serialized.contains("foo"));
41 assertTrue(serialized.contains("bar"));
43 assertEquals("serialize", "",
44 codec.serialize(ImmutableSet.of()));
45 assertEquals("serialize", "", codec.serialize(null));
48 @SuppressWarnings("unchecked")
50 public void testDeserialize() {
52 BitsCodec<String> codec = getCodec( toBitsTypeDefinition( "bit1", "bit2" ), BitsCodec.class );
54 assertEquals("deserialize", ImmutableSet.of("bit1", "bit2"), codec.deserialize(" bit1 bit2 "));
56 assertEquals("deserialize", Collections.emptySet(), codec.deserialize(""));
57 assertEquals("deserialize", Collections.emptySet(), codec.deserialize(null));
59 deserializeWithExpectedIllegalArgEx(codec, "bit1 bit3");