Alexander Afanasyev | a8bc0d8 | 2016-01-25 17:25:30 -0800 | [diff] [blame] | 1 | /* |
| 2 | * jndn-management |
| 3 | * Copyright (c) 2016, Regents of the University of California |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU Lesser General Public License, |
| 7 | * version 3, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
| 12 | * more details. |
| 13 | */ |
| 14 | package com.intel.jndn.management; |
| 15 | |
| 16 | import java.nio.ByteBuffer; |
| 17 | |
| 18 | /** |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 19 | * Helper methods for unit tests. |
Alexander Afanasyev | a8bc0d8 | 2016-01-25 17:25:30 -0800 | [diff] [blame] | 20 | */ |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 21 | public final class TestHelper { |
Alexander Afanasyev | a8bc0d8 | 2016-01-25 17:25:30 -0800 | [diff] [blame] | 22 | /** |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 23 | * Prevent instances of TestHelper. |
Alexander Afanasyev | a8bc0d8 | 2016-01-25 17:25:30 -0800 | [diff] [blame] | 24 | */ |
| 25 | private TestHelper() { |
| 26 | } |
| 27 | |
| 28 | /** |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 29 | * Construct ByteBuffer from int[]. |
| 30 | * |
| 31 | * @param array array to convert |
Alexander Afanasyev | a8bc0d8 | 2016-01-25 17:25:30 -0800 | [diff] [blame] | 32 | */ |
| 33 | public static ByteBuffer |
Alexander Afanasyev | e36e1af | 2016-02-19 18:06:05 -0800 | [diff] [blame] | 34 | bufferFromIntArray(final int[] array) { |
Alexander Afanasyev | a8bc0d8 | 2016-01-25 17:25:30 -0800 | [diff] [blame] | 35 | ByteBuffer result = ByteBuffer.allocate(array.length); |
| 36 | for (int value : array) { |
| 37 | result.put((byte) (value & 0xFF)); |
| 38 | } |
| 39 | |
| 40 | result.flip(); |
| 41 | return result; |
| 42 | } |
| 43 | } |