### Question:
TailSocket extends WebSocketAdapter { @Override public void onWebSocketText(String message) { if (isPing(message)) { sendPong(); return; } if (isStop(message)) { stopTail(); return; } Matcher m = TAIL_COMMAND.matcher(message); if (!m.matches()) { logger.warn("Unsupported command format '" + message + "', must match " + TAIL_COMMAND.pattern() + ", ignoring the command."); return; } try { File file = resolveLogFile(m.group("path")); if (file == null) { return; } float fractionOfMegabyteToRead = toFloat(m.group("amount")); long bytesToTail = round(fractionOfMegabyteToRead * 1024L * 1024L); Mode mode = "tail".equals(m.group("mode")) ? TAIL : FOLLOW; tail(file, bytesToTail, mode); } catch (IOException e) { throw new RuntimeException(e); } } TailSocket(LogFiles logFiles); @Override void onWebSocketClose(int statusCode, String reason); @Override void onWebSocketText(String message);  }### Answer:
@Test public void testFollowLogfile() throws Exception { File emptyLog = createTempFile("tailsocket-test-", ".log", getTestLogfileDirectory().getParentFile()); this.availableLogFiles.add(emptyLog); testee.onWebSocketText("follow:0.1mb:" + emptyLog.getAbsolutePath()); sleepUpTo(1, SECONDS); verifyNoTextWasSent(); write(emptyLog, "test line"); eventually(() -> assertSendTextContains("test line")); }
@Test public void testStopFollowLogfile() throws Exception { File emptyLog = createTempFile("tailsocket-test-", ".log", getTestLogfileDirectory().getParentFile()); this.availableLogFiles.add(emptyLog); testee.onWebSocketText("follow:0.1mb:" + emptyLog.getAbsolutePath()); sleepUpTo(1, SECONDS); verifyNoTextWasSent(); testee.onWebSocketText("stop"); write(emptyLog, "test line"); sleepUpTo(1, SECONDS); verifyNoTextWasSent(); }
@Test public void testHandlingOfInvalidWebSocketCommand() throws Exception { this.testee.onWebSocketText("not:valid"); verifyCommandIsIgnored(); }