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