### Question:
StringUtil { public static int byteLength(String str) { if(str == null) { return 0; } String newString = ""; try { newString = new String(str.getBytes("GB2312"), "ISO-8859-1"); return newString.length(); } catch (UnsupportedEncodingException e) { return 0; } }  static int byteLength(String str);  }### Answer:
@Test public void byte_length() { assertThat(StringUtil.byteLength(null)).isEqualTo(0); assertThat(StringUtil.byteLength("a")).isEqualTo(1); assertThat(StringUtil.byteLength("中")).isEqualTo(2); }