### Question:
QuestionsAndAnswersController implements ApplicationContextAware, PluginController { @RequestMapping(value = "{id}/open", method = RequestMethod.GET) public String openQuestion(@PathVariable("id") Long id) throws NotFoundException { Topic topic = getTypeAwarePluginTopicService().get(id, QuestionsAndAnswersPlugin.TOPIC_TYPE); getTypeAwarePluginTopicService().openTopic(topic); return "redirect:" + QuestionsAndAnswersPlugin.CONTEXT + "/" + topic.getId(); }  @RequestMapping(value = "new", method = RequestMethod.GET) String showNewQuestionPage(@RequestParam(BRANCH_ID) Long branchId, Model model, HttpServletRequest request); @RequestMapping(value = "new", method = RequestMethod.POST) String createQuestion(@Valid @ModelAttribute TopicDto topicDto, BindingResult result, Model model,
                                 @RequestParam(BRANCH_ID) Long branchId, HttpServletRequest request); @RequestMapping(value = "/resources/icon/{name}", method = RequestMethod.GET) void getIcon(HttpServletRequest request, HttpServletResponse response, @PathVariable("name") String name); @RequestMapping(value = "{id}", method = RequestMethod.GET) String showQuestion(HttpServletRequest request, Model model, @PathVariable("id") Long id); @RequestMapping(value = "{id}/canpost", method = RequestMethod.GET) @ResponseBody JsonResponse canPost(@PathVariable("id") Long questionId); @RequestMapping(value = "{questionId}/post/{answerId}", method = RequestMethod.GET) String showAnswer(@PathVariable Long questionId, @PathVariable Long answerId); @RequestMapping(value = "{id}/edit", method = RequestMethod.GET) String editQuestionPage(HttpServletRequest request, Model model, @PathVariable("id") Long id); @RequestMapping(value = "{id}/edit", method = RequestMethod.POST) String updateQuestion(@Valid @ModelAttribute TopicDto topicDto, BindingResult result, Model model,
                                 @PathVariable("id") Long id, HttpServletRequest request); @RequestMapping(value = "post/{id}/edit", method = RequestMethod.GET) String editAnswerPage(HttpServletRequest request, Model model, @PathVariable("id") Long id); @RequestMapping(value = "post/{id}/edit", method = RequestMethod.POST) String updateAnswer(@Valid @ModelAttribute PostDto postDto, BindingResult result, Model model,
                                 @PathVariable("id") Long id, HttpServletRequest request); @RequestMapping(value = "{questionId}", method = RequestMethod.POST) String create(@PathVariable("questionId") Long questionId, @Valid @ModelAttribute PostDto postDto,
                               BindingResult result, Model model, HttpServletRequest request); @RequestMapping(value = "{id}/close", method = RequestMethod.GET) String closeQuestion(@PathVariable("id") Long id); @RequestMapping(value = "{id}/open", method = RequestMethod.GET) String openQuestion(@PathVariable("id") Long id); @RequestMapping(method = RequestMethod.DELETE, value = "post/{answerId}") String deleteAnswer(@PathVariable Long answerId); @Override void setApplicationContext(ApplicationContext applicationContext); void setApiPath(String apiPath); static final int LIMIT_OF_POSTS_VALUE; static final String PLUGIN_VIEW_NAME; static final String BRANCH_ID; static final String CONTENT; static final String POST_ID; static final String COMMENT_ID; }### Answer:
@Test public void testOpenQuestionSuccess() throws Exception { Long id = 1L; Topic topic = new Topic(); topic.setId(id); when(topicService.get(id, QuestionsAndAnswersPlugin.TOPIC_TYPE)).thenReturn(topic); String result = controller.openQuestion(id); assertEquals(result, "redirect:" + QuestionsAndAnswersPlugin.CONTEXT + "/" + topic.getId()); verify(topicService).openTopic(topic); }
@Test(expectedExceptions = NotFoundException.class) public void openQuestionShouldThrowExceptionWhenQuestionNotFound() throws Exception { when(topicService.get(anyLong(), anyString())).thenThrow(new NotFoundException()); controller.openQuestion(1L); }