Example #1
0
  /*
   *  Tests that the helper object's makeBook method is called to return a
   *  Book object.
   */
  @Test
  public void testAddBook() {

    // Create a spy BookHelper object
    BookHelper spy = Mockito.spy(new BookHelper());

    // Create a BookMapDAO Object passing in our spy helper
    BookMapDAO bmd = new BookMapDAO(spy);

    // test the BookMapDAO addBook method
    bmd.addBook(AUTHOR, TITLE, CALLNO);

    // verify that the spy helper object method .makebook is called once
    Mockito.verify(spy, Mockito.times(1))
        .makeBook(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyInt());
  }
Example #2
0
  @Test
  public void testMock() {
    IBook mockBook = Mockito.mock(IBook.class);
    BookHelper bookHelper = Mockito.spy(new BookHelper());

    // Stubs the return
    Mockito.doReturn(mockBook).when(bookHelper).makeBook(AUTHOR, TITLE, CALLNO, ID);

    IBook test1 = bookHelper.makeBook(AUTHOR, TITLE, CALLNO, ID);

    // below tests the DAO
    BookMapDAO testDAO = new BookMapDAO(bookHelper);
    IBook test = testDAO.addBook(AUTHOR, TITLE, CALLNO);

    assert (test != null);
  }