### Question:
CompactEncoder { public static byte[] unpackToNibbles(byte[] str) { byte[] base = binToNibbles(str); int terminator = 0; if (base[0] < 2) { terminator = 1; } if ((base[0] & 1) == 1) { base = copyOfRange(base, 1, base.length - terminator); } else { base = copyOfRange(base, 2, base.length - terminator); } return base; }  static byte[] packNibbles(byte[] nibbles); static boolean hasTerminator(byte[] packedKey); static byte[] unpackToNibbles(byte[] str); static byte[] binToNibbles(byte[] str);  }### Answer:
@Test public void testCompactDecodeOddCompact() { byte[] test = new byte[] {0x11, 0x23, 0x45}; byte[] expected = new byte[] {1, 2, 3, 4, 5}; assertArrayEquals( "odd compact decode fail", expected, CompactEncoder.unpackToNibbles(test)); }
@Test public void testCompactDecodeEvenCompact() { byte[] test = new byte[] {0x00, 0x01, 0x23, 0x45}; byte[] expected = new byte[] {0, 1, 2, 3, 4, 5}; assertArrayEquals( "even compact decode fail", expected, CompactEncoder.unpackToNibbles(test)); }
@Test public void testCompactDecodeEvenTerminated() { byte[] test = new byte[] {0x20, 0x0f, 0x1c, (byte) 0xb8}; byte[] expected = new byte[] {0, 15, 1, 12, 11, 8, T}; assertArrayEquals( "even terminated compact decode fail", expected, CompactEncoder.unpackToNibbles(test)); }
@Test public void testCompactDecodeOddTerminated() { byte[] test = new byte[] {0x3f, 0x1c, (byte) 0xb8}; byte[] expected = new byte[] {15, 1, 12, 11, 8, T}; assertArrayEquals( "odd terminated compact decode fail", expected, CompactEncoder.unpackToNibbles(test)); }