StringUtil { public static byte[] toBytes(final String string) { if (null == string) { return new byte[0]; } try { return string.getBytes(CommonConstants.UTF_8); } catch (final UnsupportedEncodingException e) { throw new RuntimeException("Unable to convert bytes to string", e); } } private  StringUtil(); static String toString(final byte[] bytes); static byte[] toBytes(final String string); static String escapeComma(final String str); static String unescapeComma(final String escapedStr); static byte[] toCsv(final Class<?>... classes); static Set<Class<? extends T>> csvToClasses(final byte[] bytes, final Class<? extends T> clazz); static String nullIfEmpty(final String string); static final char COMMA; }
@Test public void toBytesWhenStringIsValid() { assertArrayEquals("isValid".getBytes(), StringUtil.toBytes("isValid")); }
@Test public void toBytesWhenStringIsNull() { assertArrayEquals(new byte[0], StringUtil.toBytes(null)); }