BoardController { @RequestMapping(value = "/board/{playerName}",method = RequestMethod.GET) public String board(ModelMap model, @PathVariable("playerName") String playerName) { Player player = playerService.findPlayer(playerName); if (player == null) { model.addAttribute("players", EMPTY_LIST); }else{ model.addAttribute("players", Collections.singletonList(player)); } model.addAttribute("allPlayersScreen", false); return "board"; } BoardController();   BoardController(PlayerService playerService); @RequestMapping(value = "/board/{playerName}",method = RequestMethod.GET) String board(ModelMap model, @PathVariable("playerName") String playerName); @RequestMapping(value = "/board",method = RequestMethod.GET) String boardAll(ModelMap model); @RequestMapping(value = "/leaderboard",method = RequestMethod.GET) String leaderBoard(); @RequestMapping(value = "/help") String help(); static final ArrayList<Object> EMPTY_LIST; }
@Test public void shouldCreateEmptyListWhenPlayerNotFound() { when(playerService.findPlayer(anyString())).thenReturn(null); boardController.board(model, "vasya"); assertTrue(getPlayers().isEmpty()); }
@Test public void shouldReturnPlayerWhenFound() { when(playerService.findPlayer(anyString())).thenReturn(getDummyPlayer()); boardController.board(model, "vasya"); assertEquals("vasya", getPlayers().get(0).getName()); }