@Test
public void testLongToBytes() {

    // test positive long
    long num = 42;
    byte[] bytes = Convert.longToBytes(num);
    assertTrue("Bad length of long byte array", bytes.length == 8);
    // need to flip the bytes to get right endianness back
    long l = ByteBuffer.wrap(bytes).getLong();
    assertTrue("Conversion of non-neg long to bytes failed: l = "+l,
               num == l);
    // test negative long
    num = -42;
    bytes = Convert.longToBytes(num);
    l = ByteBuffer.wrap(bytes).getLong();
    assertTrue("Conversion of negative long to bytes failed: l = "+l,
               num == l);
}