2 * Copyright (c) 2016 Cisco 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
8 package org.opendaylight.yangtools.yang.data.impl.codec;
10 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
13 import java.util.Base64;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
16 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
19 * Unit tests for BinaryCodecString.
21 * @author Thomas Pantelis
23 class BinaryCodecStringTest {
24 private static final byte[] FOUR_ELEMENTS = { 1, 2, 3, 4 };
27 void testSerialize() {
28 final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.binaryType(), BinaryCodec.class);
29 assertEquals(Base64.getEncoder().encodeToString(FOUR_ELEMENTS), codec.serialize(FOUR_ELEMENTS));
33 void testDererialize() {
34 @SuppressWarnings("unchecked")
35 final var codec = (BinaryCodec<String>)
36 TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.binaryType(), BinaryCodec.class);
37 assertArrayEquals(FOUR_ELEMENTS, codec.deserialize(Base64.getEncoder().encodeToString(FOUR_ELEMENTS)));