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.*;
13 import org.junit.Test;
14 import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
15 import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
16 import org.opendaylight.yangtools.yang.model.util.BinaryType;
18 import com.google.common.io.BaseEncoding;
21 * Unit tests for BinaryCodecString.
23 * @author Thomas Pantelis
25 public class BinaryCodecStringTest {
27 @SuppressWarnings("unchecked")
29 public void testSerialize() {
30 BinaryCodec<String> codec = getCodec( BinaryType.getInstance(), BinaryCodec.class);
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 ) );
37 @SuppressWarnings("unchecked")
39 public void testDererialize() {
40 BinaryCodec<String> codec = getCodec( BinaryType.getInstance(), BinaryCodec.class);
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 ) );