DelayedLogonTask extends TimerTask { @Override public void run() { if (networkService.isNetworkUp()) { chatState.setLogonCompleted(true); } } DelayedLogonTask(final NetworkService networkService, final ChatState chatState); @Override void run();  }
@Test public void runShouldDoNothingIfNetworkIsDown() { assertFalse(networkService.isNetworkUp()); assertFalse(chatState.isLogonCompleted()); logonTask.run(); assertFalse(chatState.isLogonCompleted()); }
@Test public void runShouldSetLogonCompletedIfNetworkIsUp() { when(networkService.isNetworkUp()).thenReturn(true); assertFalse(chatState.isLogonCompleted()); logonTask.run(); assertTrue(chatState.isLogonCompleted()); }