コード例 #1
0
  @Test
  @PrepareForTest({UtilsHibernate.class})
  public void testGetArticles() throws Exception {

    PowerMockito.mockStatic(UtilsHibernate.class);

    List<Article> articleList = new ArrayList<>();

    Article article1 = new Article();
    article1.setTitle("article1");
    articleList.add(article1);

    Article article2 = new Article();
    article2.setTitle("article2");
    articleList.add(article2);

    Mockito.when(
            articleDao.getAllArticles(
                2, 1, UtilsHibernate.getOrderByString("asc", "title"), "title", 1))
        .thenReturn(articleList);

    List<Article> articles = articleService.getArticles(2, 1, "asc", "title", 1);

    Assert.assertTrue(
        articles.get(0).getTitle().equals("article1")
            && articles.get(1).getTitle().equals("article2"));
  }
コード例 #2
0
  @Test
  @PrepareForTest({UtilsHibernate.class})
  public void testGetAllTickets() throws Exception {

    PowerMockito.mockStatic(UtilsHibernate.class);

    Mockito.when(ticketDao.getAllTickets(10, 0, UtilsHibernate.getOrderByString("ticketId", "ASC")))
        .thenReturn(ticketList);

    List<Ticket> results = ticketService.getAllTickets(10, 0, "ticketId", "ASC");

    assertTrue(results.get(0).getTitle().length() < 50);
  }
コード例 #3
0
  @Test
  @PrepareForTest({UtilsHibernate.class})
  public void testGetAllTicketsAdmin() throws Exception {

    PowerMockito.mockStatic(UtilsHibernate.class);

    Mockito.when(
            ticketDao.getAllTicketsAdmin(10, 0, UtilsHibernate.getOrderByString("ASC", "status")))
        .thenReturn(ticketList);

    List<Ticket> resultTicket = ticketService.getAllTicketsAdmin(10, 0, "ASC", "status");

    assertEquals(resultTicket, ticketList);
  }