blob: d5b7706228e9c33e8a6973b21e18dded8a9468dd [file] [log] [blame]
Yuta HIGUCHI75fb1f42014-11-19 13:56:19 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Yuta HIGUCHI75fb1f42014-11-19 13:56:19 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onlab.util;
18
19import static org.junit.Assert.*;
20
21import java.util.Arrays;
22
23import org.junit.Test;
24
25/**
26 * Test cases for byte[] pretty printer.
27 */
28public class ByteArraySizeHashPrinterTest {
29
30 /**
31 * Test method for {@link org.onlab.util.ByteArraySizeHashPrinter#toString()}.
32 */
33 @Test
34 public void testToStringNull() {
35 final byte[] none = null;
36
37 assertEquals("byte[]{null}", String.valueOf(ByteArraySizeHashPrinter.of(none)));
38 assertNull(ByteArraySizeHashPrinter.orNull(none));
39 }
40
41 /**
42 * Test method for {@link org.onlab.util.ByteArraySizeHashPrinter#toString()}.
43 */
44 @Test
45 public void testToString() {
46 final byte[] some = new byte[] {2, 5, 0, 1 };
47 final String expected = "byte[]{length=" + some.length + ", hash=" + Arrays.hashCode(some) + "}";
48
49 assertEquals(expected, String.valueOf(ByteArraySizeHashPrinter.of(some)));
50 assertNotNull(ByteArraySizeHashPrinter.orNull(some));
51 }
52
53}