3131
3232package org .scijava .io .location ;
3333
34+ import static org .junit .Assert .assertArrayEquals ;
3435import static org .junit .Assert .assertEquals ;
35- import static org .junit .Assert .assertSame ;
3636
3737import org .junit .Test ;
38- import org .scijava .io .location .BytesLocation ;
3938
4039/**
4140 * Tests {@link BytesLocation}.
@@ -47,22 +46,29 @@ public class BytesLocationTest {
4746 /** Tests {@link BytesLocation#BytesLocation(byte[])}. */
4847 @ Test
4948 public void testBytes () {
50- final byte [] digits = {3 , 1 , 4 , 1 , 5 , 9 , 2 , 6 , 5 , 3 , 5 , 8 , 9 , 7 , 9 };
49+ final byte [] digits = { 3 , 1 , 4 , 1 , 5 , 9 , 2 , 6 , 5 , 3 , 5 , 8 , 9 , 7 , 9 };
5150 final BytesLocation loc = new BytesLocation (digits );
52- assertSame (digits , loc .getByteBuffer ().array ());
53- assertEquals (0 , loc .getByteBuffer ().position ());
54- assertEquals (digits .length , loc .getByteBuffer ().remaining ());
51+
52+ final byte [] testDigits = new byte [digits .length ];
53+ loc .getByteBank ().getBytes (0 , testDigits );
54+ assertEquals (digits .length , loc .getByteBank ().getMaxPos ());
55+ assertArrayEquals (digits , testDigits );
5556 }
5657
5758 /** Tests {@link BytesLocation#BytesLocation(byte[], int, int)}. */
5859 @ Test
5960 public void testBytesOffsetLength () {
60- final byte [] digits = {3 , 1 , 4 , 1 , 5 , 9 , 2 , 6 , 5 , 3 , 5 , 8 , 9 , 7 , 9 };
61+ final byte [] digits = { 3 , 1 , 4 , 1 , 5 , 9 , 2 , 6 , 5 , 3 , 5 , 8 , 9 , 7 , 9 };
6162 final int offset = 3 , length = 5 ;
6263 final BytesLocation loc = new BytesLocation (digits , offset , length );
63- assertSame (digits , loc .getByteBuffer ().array ());
64- assertEquals (offset , loc .getByteBuffer ().position ());
65- assertEquals (length , loc .getByteBuffer ().remaining ());
64+
65+ final byte [] testDigits = new byte [digits .length ];
66+ loc .getByteBank ().getBytes (0 , testDigits );
67+ assertEquals (length , loc .getByteBank ().getMaxPos ());
68+
69+ final byte [] expectedDigits = new byte [digits .length ];
70+ System .arraycopy (digits , offset , expectedDigits , 0 , length );
71+ assertArrayEquals (expectedDigits , testDigits );
6672 }
6773
6874}
0 commit comments