Migrate yang-data-impl to JUnit5
[yangtools.git] / data / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codec / 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 package org.opendaylight.yangtools.yang.data.impl.codec;
9
10 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
12
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;
17
18 /**
19  * Unit tests for BinaryCodecString.
20  *
21  * @author Thomas Pantelis
22  */
23 class BinaryCodecStringTest {
24     private static final byte[] FOUR_ELEMENTS = { 1, 2, 3, 4 };
25
26     @Test
27     void testSerialize() {
28         final var codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.binaryType(), BinaryCodec.class);
29         assertEquals(Base64.getEncoder().encodeToString(FOUR_ELEMENTS), codec.serialize(FOUR_ELEMENTS));
30     }
31
32     @Test
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)));
38     }
39 }