@Test
public void showPage() throws NotFoundException {
long branchId = 1L;
String page = "2";
Branch branch = new Branch("name", "description");
branch.setId(branchId);
Pageable pageRequest = new PageRequest(2, 5);
Page<Topic> topicsPage = new PageImpl<>(Collections.<Topic> emptyList(), pageRequest, 0);
//set expectations
when(branchService.get(branchId)).thenReturn(branch);
when(topicFetchService.getTopics(branch, page)).thenReturn(topicsPage);
when(breadcrumbBuilder.getForumBreadcrumb(branchService.get(branchId)))
.thenReturn(new ArrayList<Breadcrumb>());
when(forumStatisticsProvider.getOnlineRegisteredUsers()).thenReturn(new ArrayList<>());
SecurityContext securityContext = mock(SecurityContext.class);
when(securityContextFacade.getContext()).thenReturn(securityContext);
Authentication authentication = mock(Authentication.class);
when(securityContext.getAuthentication()).thenReturn(authentication);
//invoke the object under test
ModelAndView mav = controller.showPage(branchId, page);
//check expectations
verify(breadcrumbBuilder).getForumBreadcrumb(branchService.get(branchId));
//check result
assertViewName(mav, "topic/topicList");
Branch actualBranch = assertAndReturnModelAttributeOfType(mav, "branch", Branch.class);
assertEquals(actualBranch.getId(), branchId);
@SuppressWarnings("unchecked")
Page<Topic> actualTopicsPage =
(Page<Topic>) assertAndReturnModelAttributeOfType(mav, "topicsPage", Page.class);
assertEquals(actualTopicsPage, topicsPage);