コード例 #1
0
  @Test
  public void testUpsertWithConnection() throws Exception {
    SavedReviewerSearch search = new SavedReviewerSearch();
    SavedReviewerSearch newSearch = new SavedReviewerSearch();
    Connection connection = EasyMock.createStrictMock(Connection.class);

    SavedReviewerSearchDAO dao =
        EasyMock.createMockBuilder(SavedReviewerSearchDAO.class)
            .withConstructor()
            .addMockedMethod("update", Connection.class, SavedReviewerSearch.class)
            .addMockedMethod("create", Connection.class, SavedReviewerSearch.class)
            .addMockedMethod("isUpdate")
            .createStrictMock();

    EasyMock.expect(dao.isUpdate(connection, search)).andReturn(false);
    EasyMock.expect(dao.create(connection, search)).andReturn(newSearch);
    EasyMock.replay(dao);
    assertEquals(
        "Wrong search returned in create case.", newSearch, dao.upsert(connection, search));
    EasyMock.verify(dao);

    EasyMock.reset(dao);
    EasyMock.expect(dao.isUpdate(connection, search)).andReturn(true);
    EasyMock.expect(dao.update(connection, search)).andReturn(true);
    EasyMock.replay(dao);
    assertEquals("Wrong search returned in update case.", search, dao.upsert(connection, search));
    EasyMock.verify(dao);
  }
コード例 #2
0
  @Test
  public void testUpsert() throws Exception {
    SavedReviewerSearch search = new SavedReviewerSearch();
    SavedReviewerSearchDAO dao =
        EasyMock.createMockBuilder(SavedReviewerSearchDAO.class)
            .withConstructor()
            .addMockedMethod("upsert", Connection.class, SavedReviewerSearch.class)
            .createStrictMock();
    ITransactionManager txMgr = EasyMock.createStrictMock(ITransactionManager.class);
    dao.setTransactionManager(txMgr);
    Connection mockConn = EasyMock.createStrictMock(Connection.class);
    EasyMock.expect(dao.upsert(mockConn, search)).andReturn(search);

    MockExecutionWithThrow.<Boolean>execute(txMgr, mockConn);
    EasyMock.replay(txMgr, mockConn, dao);
    assertEquals("Wrong search result.", search, dao.upsert(search));
    EasyMock.verify(txMgr, mockConn, dao);
  }