AdminController { @RequestMapping(method = RequestMethod.GET) public String getAdminPage(Model model) { AdminSettings settings = new AdminSettings(); model.addAttribute("adminSettings", settings); checkGameStatus(model); buildGameLevelsOptions(model, settings); buildProtocolsOptions(model, settings); prepareList(model, settings); return "admin"; } AdminController();   AdminController(TimerService timerService, GameSettingsService gameSettingsService, PlayerService playerService); @RequestMapping(params = "save", method = RequestMethod.GET) String savePlayerGame(@RequestParam("save") String name, Model model); @RequestMapping(params = "load", method = RequestMethod.GET) String loadPlayerGame(@RequestParam("load") String name, Model model); @RequestMapping(params = "remove", method = RequestMethod.GET) String removePlayer(@RequestParam("remove") String name, Model model); @RequestMapping(params = "pause", method = RequestMethod.GET) String pauseGame(Model model); @RequestMapping(params = "resume", method = RequestMethod.GET) String resumeGame(Model model); @RequestMapping(method = RequestMethod.POST) String saveSettings(AdminSettings settings, BindingResult result, Model model); @RequestMapping(method = RequestMethod.GET) String getAdminPage(Model model);  }
@Test public void shouldGetAdminPageWhenCallAdmin() { when(timerService.isPaused()).thenReturn(GAME_ACTIVE); String jsp = controller.getAdminPage(model); assertEquals("admin", jsp); verify(model).addAttribute("paused", GAME_ACTIVE); }
@Test public void shouldPrepareSettingsWhenCallAdmin() { List<String> list = list("qwe", "asd"); when(gameSettingsService.getGameLevelsList()).thenReturn(list); when(gameSettingsService.getCurrentGameLevels()).thenReturn("zxc"); String jsp = controller.getAdminPage(model); verify(model).addAttribute("levelsList", list); ArgumentCaptor<AdminSettings> captor = ArgumentCaptor.forClass(AdminSettings.class); verify(model).addAttribute(eq("adminSettings"), captor.capture()); assertEquals("zxc", captor.getValue().getSelectedLevels()); }
@Test public void shouldPreparePlayersInfoListWhenCallAdmin() { List list = new LinkedList<>(); list.add(new PlayerInfo("", false)); when(playerService.getPlayersGames()).thenReturn(list); controller.getAdminPage(model); ArgumentCaptor<AdminSettings> captor = ArgumentCaptor.forClass(AdminSettings.class); verify(model).addAttribute(eq("adminSettings"), captor.capture()); assertSame(list, captor.getValue().getPlayers()); verify(model).addAttribute(eq("paused"), anyObject()); verify(model).addAttribute(eq("levelsList"), anyObject()); verify(model).addAttribute("players", list); }
@Test public void shouldEmptyPlayersListWhenNoPlayers() { List list = new LinkedList<>(); when(playerService.getPlayersGames()).thenReturn(list); controller.getAdminPage(model); ArgumentCaptor<AdminSettings> captor = ArgumentCaptor.forClass(AdminSettings.class); verify(model).addAttribute(eq("adminSettings"), captor.capture()); assertSame(list, captor.getValue().getPlayers()); verify(model).addAttribute(eq("paused"), anyObject()); verify(model).addAttribute(eq("levelsList"), anyObject()); verify(model, never()).addAttribute("players", list); }