### Question:
CodeReviewController { @RequestMapping(value = "/reviews/new", method = RequestMethod.GET) public ModelAndView showNewCodeReviewPage(@RequestParam(BRANCH_ID) Long branchId) throws NotFoundException { TopicDraft draft = ObjectUtils.defaultIfNull( topicDraftService.getDraft(), new TopicDraft()); TopicDto dto = new TopicDto(draft); Branch branch = branchService.get(branchId); dto.getTopic().setBranch(branch); dto.getTopic().setType(TopicTypeName.CODE_REVIEW.getName()); return new ModelAndView(CODE_REVIEW_VIEW) .addObject(TOPIC_DTO, dto) .addObject(TOPIC_DRAFT, draft) .addObject(BRANCH_ID, branchId) .addObject(SUBMIT_URL, "/reviews/new?branchId=" + branchId) .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getNewTopicBreadcrumb(branch)); } @Autowired  CodeReviewController(BranchService branchService,
                                BreadcrumbBuilder breadcrumbBuilder,
                                TopicModificationService topicModificationService,
                                TopicDraftService topicDraftService,
                                RetryTemplate retryTemplate); @RequestMapping(value = "/reviews/new", method = RequestMethod.GET) ModelAndView showNewCodeReviewPage(@RequestParam(BRANCH_ID) Long branchId); @RequestMapping(value = "/reviews/new", method = RequestMethod.POST) ModelAndView createCodeReview(@Valid @ModelAttribute final TopicDto topicDto,
                                         BindingResult result,
                                         @RequestParam(BRANCH_ID) Long branchId); static final String BRANCH_ID; static final String BREADCRUMB_LIST; }### Answer:
@Test public void createPage() throws NotFoundException { when(branchService.get(BRANCH_ID)).thenReturn(branch); when(breadcrumbBuilder.getNewTopicBreadcrumb(branch)).thenReturn(new ArrayList<Breadcrumb>()); ModelAndView mav = controller.showNewCodeReviewPage(BRANCH_ID); assertViewName(mav, "codeReviewForm"); assertModelAttributeAvailable(mav, "topicDto"); long branchId = assertAndReturnModelAttributeOfType(mav, "branchId", Long.class); assertEquals(branchId, BRANCH_ID); String submitUrl = assertAndReturnModelAttributeOfType(mav, "submitUrl", String.class); assertEquals(submitUrl, "/reviews/new?branchId=" + branchId); assertModelAttributeAvailable(mav, "breadcrumbList"); }
@Test public void showNewCodeReviewPageShouldShowDraft() throws NotFoundException { Topic expectedTopic = createTopic(); TopicDraft expectedDraft = new TopicDraft(user, expectedTopic.getTitle(), expectedTopic.getBodyText()); when(topicDraftService.getDraft()).thenReturn(expectedDraft); when(branchService.get(BRANCH_ID)).thenReturn(branch); when(breadcrumbBuilder.getNewTopicBreadcrumb(branch)).thenReturn(new ArrayList<Breadcrumb>()); ModelAndView mav = controller.showNewCodeReviewPage(BRANCH_ID); TopicDto topicDto = assertAndReturnModelAttributeOfType(mav, "topicDto", TopicDto.class); Topic topic = topicDto.getTopic(); assertEquals(topic.getTitle(), expectedDraft.getTitle()); assertEquals(topicDto.getBodyText(), expectedDraft.getContent()); }