summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/fs4/test/HexByteIteratorTestCase.java
blob: b07363d7df28b2f3179cac1e33f0b4a4c3a67793 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.fs4.test;

import java.nio.ByteBuffer;

import com.yahoo.fs4.HexByteIterator;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * Test of HexByteIterator
 *
 * @author tonytv
 */
public class HexByteIteratorTestCase {

    @Test
    public void testHexByteIterator() {
        int[] numbers = { 0x00, 0x01, 0xDE, 0xAD, 0xBE, 0xEF, 0xFF };

        HexByteIterator i = new HexByteIterator(
                ByteBuffer.wrap(toBytes(numbers)));

        assertEquals("00", i.next());
        assertEquals("01", i.next());
        assertEquals("DE", i.next());
        assertEquals("AD", i.next());
        assertEquals("BE", i.next());
        assertEquals("EF", i.next());
        assertEquals("FF", i.next());
        assertTrue(!i.hasNext());
    }

    private byte[] toBytes(int[] ints) {
        byte[] bytes = new byte[ints.length];
        for (int i=0; i<bytes.length; ++i)
            bytes[i] = (byte)ints[i];
        return bytes;
    }
}