@Test
public void getShortMessageUserDataHeader() {

    Assert.assertNull(GsmUtil.getShortMessageUserDataHeader(null));
    Assert.assertArrayEquals(HexUtil.toByteArray("00"), GsmUtil.getShortMessageUserDataHeader(HexUtil.toByteArray("0002")));
    Assert.assertArrayEquals(HexUtil.toByteArray("0102"), GsmUtil.getShortMessageUserDataHeader(HexUtil.toByteArray("0102")));
    Assert.assertArrayEquals(HexUtil.toByteArray("0102"), GsmUtil.getShortMessageUserDataHeader(HexUtil.toByteArray("01020304050607")));
    // make sure "signed" byte of user data header works
    Assert.assertArrayEquals(HexUtil.toByteArray("800001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607"), GsmUtil.getShortMessageUserDataHeader(HexUtil.toByteArray("80000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708")));
    try {
        // UDH length exceeds payload
        Assert.assertArrayEquals(HexUtil.toByteArray("01"), GsmUtil.getShortMessageUserDataHeader(HexUtil.toByteArray("01")));
        Assert.fail();
    } catch (IllegalArgumentException e) {
        // correct behavior
    }
}