SessionMonitor { public void triggerVerificationIfNecessary() { final Session session = sessionManager.getActiveSession(); final long currentTime = time.getCurrentTimeMillis(); final boolean startVerification = session != null && monitorState.beginVerification(currentTime); if (startVerification) { executorService.submit(this::verifyAll); } } SessionMonitor(SessionManager<T> sessionManager, ExecutorService executorService,
            SessionVerifier<T> sessionVerifier);   SessionMonitor(SessionManager<T> sessionManager, SystemCurrentTimeProvider time,
            ExecutorService executorService, MonitorState monitorState, SessionVerifier
            sessionVerifier); void monitorActivityLifecycle(ActivityLifecycleManager activityLifecycleManager); void triggerVerificationIfNecessary();  }
@Test public void testTriggerVerificationIfNecessary_respectsFalseStartVerification() { when(mockMonitorState.beginVerification(anyLong())).thenReturn(false); sessionMonitor.triggerVerificationIfNecessary(); verifyZeroInteractions(mockExecutorService); }
@Test public void testTriggerVerificationIfNecessary_doesNotTriggerIfNoActiveSession() { when(mockMonitorState.beginVerification(anyLong())).thenReturn(true); when(mockSessionManager.getActiveSession()).thenReturn(null); sessionMonitor.triggerVerificationIfNecessary(); verifyZeroInteractions(mockExecutorService); }
@Test public void testTriggerVerificationIfNecessary_submitsRunnable() { when(mockMonitorState.beginVerification(anyLong())).thenReturn(true); sessionMonitor.triggerVerificationIfNecessary(); verify(mockExecutorService).submit(any(Runnable.class)); }
@Test public void testVerifySession_callsAccountService() { when(mockMonitorState.beginVerification(anyLong())).thenReturn(Boolean.TRUE); sessionMonitor.triggerVerificationIfNecessary(); final ArgumentCaptor<Runnable> runnableArgumentCaptor = ArgumentCaptor.forClass(Runnable .class); verify(mockExecutorService).submit(runnableArgumentCaptor.capture()); final Runnable tasks = runnableArgumentCaptor.getValue(); tasks.run(); verify(mockSessionVerifier).verifySession(any(Session.class)); }