### Question:
UnixDomainSocket implements IOFacade { @Override public String read() throws IOException { CharBuffer response = CharBuffer.allocate(bufferSize); String result = ""; do { response.clear(); reader.read(response); result += new String(response.array(), response.arrayOffset(), response.position()); } while (response.get(response.position() - 1) != '\n'); return result; } UnixDomainSocket(String ipcSocketPath);  UnixDomainSocket(String ipcSocketPath, int bufferSize);   UnixDomainSocket(InputStreamReader reader, PrintWriter writer, int bufferSize); @Override void write(String payload); @Override String read(); @Override void close();  }### Answer:
@Test public void testIpcService() throws IOException { unixDomainSocket = new UnixDomainSocket(reader, writer, RESPONSE.length()); doAnswer(invocation -> { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append(RESPONSE); return RESPONSE.length(); }).when(reader).read(any(CharBuffer.class)); runTest(); }
@Test public void testReadExceedsBuffer() throws IOException { int bufferSize = RESPONSE.length() / 3; unixDomainSocket = new UnixDomainSocket(reader, writer, RESPONSE.length() / 3); doAnswer(invocation -> { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append(RESPONSE.substring(0, bufferSize)); return RESPONSE.length(); }) .doAnswer(invocation -> { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append( RESPONSE.substring(bufferSize, bufferSize * 2)); return RESPONSE.length(); }).doAnswer(invocation -> { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append( RESPONSE.substring(bufferSize * 2, bufferSize * 3)); return RESPONSE.length(); }) .doAnswer(invocation -> { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append( RESPONSE.substring(bufferSize * 3, RESPONSE.length())); return RESPONSE.length(); }) .when(reader).read(any(CharBuffer.class)); runTest(); }
@Test public void testSlowResponse() throws Exception { String response = "{\"jsonrpc\":\"2.0\",\"id\":1," + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n"; unixDomainSocket = new UnixDomainSocket(reader, writer, response.length()); final LinkedList<String> segments = new LinkedList<>(); segments.add(response.substring(0, 50)); segments.add(response.substring(50)); doAnswer(invocation -> { String segment = segments.poll(); if (segment == null) { return 0; } else { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append(segment); return segment.length(); } }).when(reader).read(any(CharBuffer.class)); IpcService ipcService = new IpcService() { @Override protected IOFacade getIO() { return unixDomainSocket; } }; ipcService.send(new Request(), Web3ClientVersion.class); }