コード例 #1
0
  @Test
  public void testGetTopic() throws NotFoundException {
    Topic expectedTopic = new Topic(user, "title");
    when(topicDao.isExist(999L)).thenReturn(true);
    when(topicDao.get(999L)).thenReturn(expectedTopic);

    int viewsCount = expectedTopic.getViews();

    Topic actualTopic = topicFetchService.get(999L);

    assertEquals(actualTopic.getViews(), viewsCount + 1);
    assertEquals(actualTopic, expectedTopic, "Topics aren't equal");
    verify(topicDao).isExist(999L);
    verify(topicDao).get(999L);
  }
コード例 #2
0
 /**
  * Deactivates branch updates subscription for the current user
  *
  * @param id identifies topic to unsubscribe from
  * @throws NotFoundException if no object is found for id given
  */
 @RequestMapping("topics/{id}/unsubscribe")
 @ResponseBody
 public ModelAndView unsubscribeFromTopic(
     @PathVariable Long id,
     @RequestHeader(value = "X-Requested-With", defaultValue = "NotAjax") String header)
     throws NotFoundException {
   Topic topic = topicFetchService.get(id);
   subscriptionService.toggleTopicSubscription(topic);
   if (header.equals("NotAjax")) {
     // redirect to new page
     return new ModelAndView("redirect:/topics/" + id);
   } else {
     // no redirecting, perform AJAX request
     return null;
   }
 }
コード例 #3
0
  @Test(expectedExceptions = {NotFoundException.class})
  public void testGetTopicWithIncorrectId() throws NotFoundException {
    when(topicDao.isExist(333L)).thenReturn(false);

    topicFetchService.get(333L);
  }