### Question:
BinaryReader { public String readUnicodeString(long index) throws IOException { StringBuffer buffer = new StringBuffer(); while (index < length()) { int ch = readUnsignedShort(index); if (ch == 0) { break; } buffer.append((char) ch); index += 2; } return buffer.toString().trim(); } BinaryReader(ByteProvider provider, boolean isLittleEndian); BinaryReader clone(int newIndex); boolean isLittleEndian(); void setLittleEndian(boolean isLittleEndian); long length(); boolean isValidIndex(int index); boolean isValidIndex(long index); int align(int alignValue); void setPointerIndex(int index); void setPointerIndex(long index); long getPointerIndex(); byte peekNextByte(); short peekNextShort(); int peekNextInt(); long peekNextLong(); byte readNextByte(); int readNextUnsignedByte(); short readNextShort(); int readNextUnsignedShort(); int readNextInt(); long readNextUnsignedInt(); long readNextLong(); String readNextAsciiString(); String readNextNullTerminatedAsciiString(); String readNextAsciiString(int length); String readNextUnicodeString(); String readNextUnicodeString(int length); byte[] readNextByteArray(int nElements); short[] readNextShortArray(int nElements); int[] readNextIntArray(int nElements); long[] readNextLongArray(int nElements); String readAsciiString(long index); String readAsciiString(long index, int length); String readTerminatedString(long index, char termChar); String readTerminatedString(long index, String termChars); String readFixedLenAsciiString(long index, int len); String readUnicodeString(long index); String readUnicodeString(long index, int length); byte readByte(long index); int readUnsignedByte(long index); short readShort(long index); int readUnsignedShort(long index); int readInt(long index); long readUnsignedInt(long index); int readInt(long index, int minClamp, int maxClamp); long readLong(long index); byte[] readByteArray(long index, int nElements); short[] readShortArray(long index, int nElements); int[] readIntArray(long index, int nElements); long[] readLongArray(long index, int nElements); String[] readAsciiStringArray(long index, int nElements); ByteProvider getByteProvider(); final static int SIZEOF_BYTE; final static int SIZEOF_SHORT; final static int SIZEOF_INT; final static int SIZEOF_LONG; }### Answer:
@Test public void testReadUnicodeString_LE() throws IOException { BinaryReader br = br(true, 1, 1, 1, 'A', 0, 'B', 0, 'C', 0, 0, 0x80, 0); assertEquals("ABC\u8000", br.readUnicodeString(3, 4)); }
@Test public void testReadUnicodeString_BE() throws IOException { BinaryReader br = br(false, 1, 1, 1, 0, 'A', 0, 'B', 0, 'C', 0x80, 0, 0); assertEquals("ABC\u8000", br.readUnicodeString(3, 4)); }
@Test public void testReadTerminatedUnicodeString_LE() throws IOException { BinaryReader br = br(true, 1, 1, 1, 'A', 0, 'B', 0, 'C', 0, 0, 0x80, 0, 0); assertEquals("ABC\u8000", br.readUnicodeString(3)); }
@Test public void testReadTerminatedUnicodeString_BE() throws IOException { BinaryReader br = br(false, 1, 1, 1, 0, 'A', 0, 'B', 0, 'C', 0x80, 0, 0, 0); assertEquals("ABC\u8000", br.readUnicodeString(3)); }