Scripted update of if statements
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codecs / BinaryCodecStringTest.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
13 import org.junit.Test;
14 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
15 import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
16 import org.opendaylight.yangtools.yang.model.util.BinaryType;
17
18 import com.google.common.io.BaseEncoding;
19
20 /**
21  * Unit tests for BinaryCodecString.
22  *
23  * @author Thomas Pantelis
24  */
25 public class BinaryCodecStringTest {
26
27     @SuppressWarnings("unchecked")
28     @Test
29     public void testSerialize() {
30         BinaryCodec<String> codec = getCodec( BinaryType.getInstance(), BinaryCodec.class);
31
32         assertEquals( "serialize", BaseEncoding.base64().encode( new byte[]{1,2,3,4} ),
33                       codec.serialize( new byte[]{1,2,3,4} ) );
34         assertEquals( "serialize", "", codec.serialize( null ) );
35     }
36
37     @SuppressWarnings("unchecked")
38     @Test
39     public void testDererialize() {
40         BinaryCodec<String> codec = getCodec( BinaryType.getInstance(), BinaryCodec.class);
41
42         assertArrayEquals( "deserialize", new byte[]{1,2,3,4},
43                       codec.deserialize( BaseEncoding.base64().encode( new byte[]{1,2,3,4} ) ) );
44         assertEquals( "deserialize", null, codec.deserialize( null ) );
45     }
46 }