@Test
public void testPackIntToByteArray() {

  for (int i = 0; i < 0x80; i++) {
    final byte[] array = JBBPUtils.packInt(i);
    assertEquals(1, array.length);
    assertEquals(i, array[0] & 0xFF);
  }
  final Random rnd = new Random(1234);
  for (int i = 0; i < 1000; i++) {
    final int generated = rnd.nextInt(0x7FFFFFFF);
    final byte[] array = JBBPUtils.packInt(generated);
    if ((generated & 0xFFFFFF80) == 0) {
      assertEquals(1, array.length);
      assertEquals(i, array[0] & 0xFF);
    } else if ((generated & 0xFFFF0000) == 0) {
      assertEquals(3, array.length);
      assertEquals(0x80, array[0] & 0xFF);
      assertEquals(generated >>> 8, array[1] & 0xFF);
      assertEquals(generated & 0xFF, array[2] & 0xFF);
    } else {
      assertEquals(5, array.length);
      assertEquals(0x81, array[0] & 0xFF);
      assertEquals((generated >>> 24) & 0xFF, array[1] & 0xFF);
      assertEquals((generated >>> 16) & 0xFF, array[2] & 0xFF);
      assertEquals((generated >>> 8) & 0xFF, array[3] & 0xFF);
      assertEquals(generated & 0xFF, array[4] & 0xFF);
    }
  }
}