Address FIXME for QueuedNotificationManager
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / test / codecs / BitsCodecStringTest.java
1 /*
2  * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.data.impl.test.codecs;
10
11 import static org.junit.Assert.*;
12 import java.util.Collections;
13 import org.junit.Test;
14
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;
18
19 import org.opendaylight.yangtools.yang.data.api.codec.BitsCodec;
20 import com.google.common.collect.ImmutableSet;
21
22 /**
23  * Unit tests for BitsCodecString.
24  *
25  * @author Thomas Pantelis
26  *
27  */
28 public class BitsCodecStringTest {
29
30     @SuppressWarnings("unchecked")
31     @Test
32     public void testSerialize() {
33
34         BitsCodec<String> codec = getCodec( toBitsTypeDefinition( "foo" ), BitsCodec.class );
35
36         ImmutableSet<String> toSerialize = ImmutableSet.of("foo", "bar");
37
38         String serialized = codec.serialize(toSerialize);
39         assertNotNull(serialized);
40         assertTrue(serialized.contains("foo"));
41         assertTrue(serialized.contains("bar"));
42
43         assertEquals("serialize", "",
44                 codec.serialize(ImmutableSet.of()));
45         assertEquals("serialize", "", codec.serialize(null));
46     }
47
48     @SuppressWarnings("unchecked")
49     @Test
50     public void testDeserialize() {
51
52         BitsCodec<String> codec = getCodec( toBitsTypeDefinition( "bit1", "bit2" ), BitsCodec.class );
53
54         assertEquals("deserialize", ImmutableSet.of("bit1", "bit2"), codec.deserialize("  bit1 bit2     "));
55
56         assertEquals("deserialize", Collections.emptySet(), codec.deserialize(""));
57         assertEquals("deserialize", Collections.emptySet(), codec.deserialize(null));
58
59         deserializeWithExpectedIllegalArgEx(codec, "bit1 bit3");
60     }
61 }