@Test public void test_edit() { Long id = 1l; when(rankingController.rankingDao.findById(id)).thenReturn(TestObjects.createSampleRanking()); ModelMap modelMap = rankingController.edit(id); verify(rankingController.rankingDao).findById(id); assertNotNull(modelMap.get("ranking")); }
@Test public void test_save() { Long id = 1l; Ranking ranking = TestObjects.createSampleRanking(); when(rankingController.rankingDao.findById(id)).thenReturn(ranking); String redirect = rankingController.save(id, "Title"); verify(rankingController.rankingDao).save(ranking); assertEquals("redirect:show.do?id=1", redirect); }
@Test public void test_delete() { Long id = 1l; Ranking ranking = TestObjects.createSampleRanking(); when(rankingController.rankingDao.findById(id)).thenReturn(ranking); String redirect = rankingController.delete(id); verify(rankingController.rankingDao).findById(id); verify(rankingController.rankingDao).delete(ranking); assertEquals("redirect:list.do", redirect); }
@Test public void test_list() { List<Ranking> rankingList = new ArrayList<Ranking>(); rankingList.add(TestObjects.createSampleRanking()); when(rankingController.rankingDao.findAll()).thenReturn(rankingList); ModelMap modelMap = rankingController.list(); verify(rankingController.rankingDao).findAll(); assertNotNull(modelMap.get("rankings")); assertTrue(((List<Ranking>) modelMap.get("rankings")).size() == 1); }