ApplicationLogListener implements AndroidLogcatService.LogcatListener { @Override public void onLogLineReceived(@NotNull LogCatMessage line) { if (!myPackageName.equals(line.getHeader().getAppName()) || myPid != line.getHeader().getPid()) { myActiveHeader = null; return; } String message; if (!line.getHeader().equals(myActiveHeader)) { myActiveHeader = line.getHeader(); message = formatLogLine(line); } else { message = AndroidLogcatFormatter.CONTINUATION_INDENT + line.getMessage(); } Key key = AndroidLogcatUtils.getProcessOutputType(myActiveHeader.getLogLevel()); notifyTextAvailable(message + "\n", key); } ApplicationLogListener(@NotNull String packageName, int pid); @Override void onLogLineReceived(@NotNull LogCatMessage line);  }
@Test public void onLogLineReceived() { LogcatListener listener = new TestApplicationLogListener("com.google.myapplication", 24314); Instant timestamp = Instant.parse("2018-04-03T20:27:49.161Z"); LogCatHeader header = new LogCatHeader(LogLevel.INFO, 24314, 24314, "com.google.myapplication", "MainActivity", timestamp); listener.onLogLineReceived(new LogCatMessage(header, "Line 1")); listener.onLogLineReceived(new LogCatMessage(header, "Line 2")); listener.onLogLineReceived(new LogCatMessage(header, "Line 3")); Object expected = "I/MainActivity: Line 1\n" + " Line 2\n" + " Line 3\n"; assertEquals(expected, listener.toString()); }