### Question:
HexString implements Serializable { @Override public String toString() { return toString(this.bytes); } HexString(String hexString); private  HexString(byte[] bytes); byte[] getBytes(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); static HexString valueOf(byte[] bytes); static String toString(byte[] bytes); static String toString(byte[] bytes, int offset, int length); static char[] toChars(byte[] bytes); static char[] toChars(byte[] bytes, int offset, int length); static byte[] toBytes(String hexString);  }### Answer:
@Test public void shouldConvertToString() throws Exception { String s = HexString.toString(BYTES); assertThat(s, is(equalTo(STRING))); }
@Test public void shouldCovertPartialToString() throws Exception { assertThat(HexString.toString(BYTES, 1, 2), is(equalTo("0102"))); assertThat(HexString.toString(BYTES, BYTES.length - 1, 1), is(equalTo("FF"))); assertThat(HexString.toString(BYTES, 0, 1), is(equalTo("00"))); }
@Test public void shouldNotAllowOffsetLessThanZeroForToString() throws Exception { this.thrown.expect(IndexOutOfBoundsException.class); HexString.toString(BYTES, -1, 2); }
@Test public void shouldNotAllowOffsetMoreThanNumberOfBytesForToString() throws Exception { this.thrown.expect(IndexOutOfBoundsException.class); HexString.toString(BYTES, BYTES.length + 1, 2); }
@Test public void shouldNotAllowLengthLessThanZeroForToString() throws Exception { this.thrown.expect(IndexOutOfBoundsException.class); HexString.toString(BYTES, 0, -1); }
@Test public void shouldNotAllowLengthMoreThanNumberOfBytesForToString() throws Exception { this.thrown.expect(IndexOutOfBoundsException.class); HexString.toString(BYTES, 1, BYTES.length); }
@Test public void shouldNotAllowNullBytesOnToString() throws Exception { this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("Bytes must not be null"); HexString.toString(null); }