Lynx { public synchronized void restart() { Logcat.Listener previousListener = logcat.getListener(); logcat.stopReading(); logcat.interrupt(); logcat = (Logcat) logcat.clone(); logcat.setListener(previousListener); lastNotificationTime = 0; tracesToNotify.clear(); logcat.start(); } Lynx(Logcat logcat, MainThread mainThread, TimeProvider timeProvider); synchronized void setConfig(LynxConfig lynxConfig); LynxConfig getConfig(); void startReading(); void stopReading(); synchronized void restart(); synchronized void registerListener(Listener lynxPresenter); synchronized void unregisterListener(Listener lynxPresenter);  }
@Test public void shouldKeepLogcatListenerOnRestart() { Logcat.Listener logcatListener = startLogcat(); lynx.restart(); verify(logcat).setListener(logcatListener); }
@Test public void shouldStartClonedLogcatOnRestart() { lynx.restart(); verify(logcat).start(); }
@Test public void shouldRemovePendingTracesToNotifyOnRestart() throws IllegalTraceException { givenCurrentTimes(NOW, NOW + 1, NOW + 2, NOW + 30); Logcat.Listener logcatListener = startLogcat(); logcatListener.onTraceRead(ANY_TRACE_MATCHING_FILTER_WTF); logcatListener.onTraceRead(ANY_TRACE_MATCHING_FILTER_VERBOSE); lynx.restart(); logcatListener.onTraceRead(ANY_TRACE_MATCHING_FILTER_DEBUG); List<Trace> tracesBeforeReset = generateTraces(ANY_TRACE_MATCHING_FILTER_VERBOSE); verify(listener, never()).onNewTraces(tracesBeforeReset); List<Trace> tracesAfterReset = generateTraces(ANY_TRACE_MATCHING_FILTER_DEBUG); verify(listener).onNewTraces(tracesAfterReset); }