### Question:
GameLoop implements Runnable { public void singleRun() { if (lastInvocation == 0) { lastInvocation = System.currentTimeMillis(); runtime.getEventManager().fire(new SceneStarted()); return; } long theCurrentTime = System.currentTimeMillis(); long theGameTime = theCurrentTime - statistics.getStartTime(); long theElapsedTime = theCurrentTime - lastInvocation; if (theElapsedTime > 0) { try { long theNumberOfTicks = statistics.incrementTicks(); statistics.beginGameLoop(); Map<GameSystem, GameSystemWork> theFutures = new HashMap<>(); for (GameSystem theSystem : runtime.getSystems()) { GameSystemWork theWork = theSystem.proceedGame(theNumberOfTicks, theGameTime, theElapsedTime); theWork.runInFrame(); theFutures.put(theSystem, theWork); }; for (GameView theGameView : gameViews) { theGameView.renderGame(theGameTime, theElapsedTime, scene, statistics); } for (Map.Entry<GameSystem, GameSystemWork> theEntry : theFutures.entrySet()) { theEntry.getValue().runAfterFrame(); } lastInvocation = theCurrentTime; } catch (Exception e) { runtime.getEventManager().fire(new SystemException(e)); } finally { statistics.endGameLoop(); } } } GameLoop(GameScene aScene, GameView aHumanGameView, GameRuntime aRuntime); void addGameView(GameView aNewGameView); GameView getHumanGameView(); GameScene getScene(); @Override void run(); void singleRunOnlyUpdateGameView(); void singleRun(); void shutdown(); boolean isShutdown();  }### Answer:
@Test public void testSingleRun() throws Exception { GameScene theScene = mock(GameScene.class); GameView theGameView = mock(GameView.class); GameRuntime theRuntime = mock(GameRuntime.class); GameEventManager theEventManager = mock(GameEventManager.class); when(theRuntime.getEventManager()).thenReturn(theEventManager); GameSystemWork theWork = mock(GameSystemWork.class); GameSystem theSystem = mock(GameSystem.class); when(theSystem.proceedGame(anyLong(), anyLong(), anyLong())).thenReturn(theWork); when(theRuntime.getSystems()).thenReturn(new GameSystem[] {theSystem}); GameLoop theLoop = new GameLoop(theScene, theGameView, theRuntime); theLoop.singleRun(); Thread.sleep(10); theLoop.singleRun(); verify(theSystem).proceedGame(anyLong(), anyLong(), anyLong()); verify(theGameView).renderGame(anyLong(), anyLong(), eq(theScene), any(RuntimeStatistics.class)); verify(theWork, times(1)).runInFrame(); verify(theWork, times(1)).runAfterFrame(); assertEquals(1, theLoop.getStatistics().getNumberTicks()); }
@Test public void testSingleRunError() throws Exception { GameScene theScene = mock(GameScene.class); GameView theGameView = mock(GameView.class); GameRuntime theRuntime = mock(GameRuntime.class); GameEventManager theManager = mock(GameEventManager.class); when(theRuntime.getEventManager()).thenReturn(theManager); GameLoop theLoop = new GameLoop(theScene, theGameView, theRuntime); theLoop.singleRun(); Thread.sleep(10); theLoop.singleRun(); verify(theManager, times(2)).fire(any(GameEvent.class)); }