@Test
public void encode() throws Exception {

    // euro currency symbol
    String str0 = "\u20ac";
    byte[] bytes = null;
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("1B65"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_PACKED_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("9B32"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UCS_2);
    Assert.assertArrayEquals(HexUtil.toByteArray("20AC"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-16BE"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UCS_2LE);
    Assert.assertArrayEquals(HexUtil.toByteArray("AC20"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-16LE"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UTF_8);
    Assert.assertArrayEquals(HexUtil.toByteArray("E282AC"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-8"), bytes);
    // latin-1 doesn't contain the euro symbol - replace with '?'
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_ISO_8859_1);
    Assert.assertArrayEquals(HexUtil.toByteArray("3F"), bytes);
    Assert.assertArrayEquals(str0.getBytes("ISO-8859-1"), bytes);
    // latin-9 does contain the euro symbol
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_ISO_8859_15);
    Assert.assertArrayEquals(HexUtil.toByteArray("A4"), bytes);
    Assert.assertArrayEquals(str0.getBytes("ISO-8859-15"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_AIRWIDE_IA5);
    Assert.assertArrayEquals(HexUtil.toByteArray("1B65"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFD2_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("1B65"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFTR_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("1B65"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_TMOBILENL_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("80"), bytes);
    // longer string with @ symbol in-between
    str0 = "Hello @ World";
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("48656C6C6F200020576F726C64"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_PACKED_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("C8329BFD060140D7B79C4D06"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UCS_2);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("00480065006C006C006F0020004000200057006F0072006C0064"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-16BE"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UCS_2LE);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("480065006C006C006F0020004000200057006F0072006C006400"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-16LE"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UTF_8);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("48656C6C6F204020576F726C64"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-8"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_ISO_8859_1);
    Assert.assertArrayEquals(HexUtil.toByteArray("48656C6C6F204020576F726C64"), bytes);
    Assert.assertArrayEquals(str0.getBytes("ISO-8859-1"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_ISO_8859_15);
    Assert.assertArrayEquals(HexUtil.toByteArray("48656C6C6F204020576F726C64"), bytes);
    Assert.assertArrayEquals(str0.getBytes("ISO-8859-15"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_AIRWIDE_IA5);
    Assert.assertArrayEquals(HexUtil.toByteArray("48656C6C6F200020576F726C64"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFD2_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("48656C6C6F204020576F726C64"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFTR_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("48656C6C6F204020576F726C64"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_TMOBILENL_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("48656C6C6F200020576F726C64"), bytes);
    // longer string with @ symbol in-between
    str0 = "JoeyBlue";
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("4A6F6579426C7565"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_PACKED_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("CA77392F64D7CB"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UCS_2);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("004A006F006500790042006C00750065"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-16BE"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UCS_2LE);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("4A006F006500790042006C0075006500"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-16LE"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UTF_8);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("4A6F6579426C7565"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-8"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_ISO_8859_1);
    Assert.assertArrayEquals(HexUtil.toByteArray("4A6F6579426C7565"), bytes);
    Assert.assertArrayEquals(str0.getBytes("ISO-8859-1"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_ISO_8859_15);
    Assert.assertArrayEquals(HexUtil.toByteArray("4A6F6579426C7565"), bytes);
    Assert.assertArrayEquals(str0.getBytes("ISO-8859-15"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_AIRWIDE_IA5);
    Assert.assertArrayEquals(HexUtil.toByteArray("4A6F6579426C7565"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFD2_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("4A6F6579426C7565"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFTR_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("4A6F6579426C7565"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_TMOBILENL_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("4A6F6579426C7565"), bytes);
    // longer string with @ symbol in-between
    str0 = "{}[]$";
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("1B281B291B3C1B3E02"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_PACKED_GSM);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("1BD426B5E16D7C02"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UCS_2);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("007B007D005B005D0024"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-16BE"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UCS_2LE);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("7B007D005B005D002400"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-16LE"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_UTF_8);
    //logger.debug(HexUtil.toHexString(bytes));
    Assert.assertArrayEquals(HexUtil.toByteArray("7B7D5B5D24"), bytes);
    Assert.assertArrayEquals(str0.getBytes("UTF-8"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_ISO_8859_1);
    Assert.assertArrayEquals(HexUtil.toByteArray("7B7D5B5D24"), bytes);
    Assert.assertArrayEquals(str0.getBytes("ISO-8859-1"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_ISO_8859_15);
    Assert.assertArrayEquals(HexUtil.toByteArray("7B7D5B5D24"), bytes);
    Assert.assertArrayEquals(str0.getBytes("ISO-8859-15"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_AIRWIDE_IA5);
    Assert.assertArrayEquals(HexUtil.toByteArray("1B281B291B3C1B3E02"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFD2_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("1B281B291B3C1B3E24"), bytes);
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFTR_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("1B281B291B3C1B3E24"), bytes);
    // {}[] not supported
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_TMOBILENL_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("3F3F3F3F02"), bytes);
    // chars specifically to vodafone-turkey
    //str0 = "$@£¤¥§ÄÅßñΓΔΘΩ€";
    str0 = "$@\u00a3\u00a4\u00a5\u00a7\u00c4\u00c5\u00df\u00f1\u0393\u0394\u0398\u03a9\u20ac";
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_VFTR_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("2440A3A4A5A7C4C5DFF1137F19151B65"), bytes);
    // form feed is an escape code in GSM
    str0 = "\f\f";
    bytes = CharsetUtil.encode(str0, CharsetUtil.CHARSET_GSM);
    Assert.assertArrayEquals(HexUtil.toByteArray("1B0A1B0A"), bytes);
}