Yuta HIGUCHI | 75fb1f4 | 2014-11-19 13:56:19 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Yuta HIGUCHI | 75fb1f4 | 2014-11-19 13:56:19 -0800 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onlab.util; |
| 18 | |
| 19 | import static org.junit.Assert.*; |
| 20 | |
| 21 | import java.util.Arrays; |
| 22 | |
| 23 | import org.junit.Test; |
| 24 | |
| 25 | /** |
| 26 | * Test cases for byte[] pretty printer. |
| 27 | */ |
| 28 | public 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 | } |