@Test public void testResultFromResultSet() throws Exception { SavedReviewerSearchDAO dao = new SavedReviewerSearchDAO(); ResultSet resultSet = EasyMock.createStrictMock(ResultSet.class); Date createdDate = new Date(); int customerId = 56; int userId = 32422; int msgTypeId = 2342; String name = "myName"; String queryType = "myQueryType"; String jsonData = "this is my json data but I don't check that it is json."; EasyMock.expect(resultSet.getString(1)).andReturn(name); EasyMock.expect(resultSet.getInt(2)).andReturn(customerId); EasyMock.expect(resultSet.getInt(3)).andReturn(userId); EasyMock.expect(resultSet.getInt(4)).andReturn(msgTypeId); EasyMock.expect(resultSet.getString(5)).andReturn(queryType); EasyMock.expect(resultSet.getString(6)).andReturn(jsonData); EasyMock.expect(resultSet.getTimestamp(7)).andReturn(new Timestamp(createdDate.getTime())); EasyMock.replay(resultSet); SavedReviewerSearch search = dao.resultFromResultSet(resultSet); EasyMock.verify(resultSet); assertEquals("Wrong created date.", createdDate, search.getCreatedDate()); assertEquals("Wrong customer id.", customerId, search.getCustomerId()); assertEquals("Wrong user id.", userId, search.getSearchUserId()); assertEquals("Wrong msg type id.", msgTypeId, search.getMessageTypeId()); assertEquals("Wrong name.", name, search.getSearchName()); assertEquals("Wrong query type.", queryType, search.getQueryType()); assertEquals("Wrong json data.", jsonData, search.getJsonData()); // now with no date EasyMock.reset(resultSet); EasyMock.expect(resultSet.getString(1)).andReturn(name); EasyMock.expect(resultSet.getInt(2)).andReturn(customerId); EasyMock.expect(resultSet.getInt(3)).andReturn(userId); EasyMock.expect(resultSet.getInt(4)).andReturn(msgTypeId); EasyMock.expect(resultSet.getString(5)).andReturn(queryType); EasyMock.expect(resultSet.getString(6)).andReturn(jsonData); EasyMock.expect(resultSet.getTimestamp(7)).andReturn(null); EasyMock.replay(resultSet); search = dao.resultFromResultSet(resultSet); EasyMock.verify(resultSet); assertNull("Created date should not be set.", search.getCreatedDate()); }
@Test public void testUpdatePreparedStatementForCreate() throws Exception { SavedReviewerSearch search = new SavedReviewerSearch(); int customerId = 56; int userId = 32422; int msgTypeId = 2342; String name = "myName"; String queryType = "myQueryType"; String jsonData = "this is my json data but I don't check that it is json."; search.setCustomerId(customerId); search.setSearchUserId(userId); search.setMessageTypeId(msgTypeId); search.setSearchName(name); search.setQueryType(queryType); search.setJsonData(jsonData); SavedReviewerSearchDAO dao = new SavedReviewerSearchDAO(); PreparedStatement preparedStatement = EasyMock.createStrictMock(PreparedStatement.class); preparedStatement.setString(1, search.getSearchName()); EasyMock.expectLastCall(); preparedStatement.setInt(2, search.getCustomerId()); EasyMock.expectLastCall(); preparedStatement.setInt(3, search.getSearchUserId()); EasyMock.expectLastCall(); preparedStatement.setInt(4, search.getMessageTypeId()); EasyMock.expectLastCall(); preparedStatement.setString(5, search.getQueryType()); EasyMock.expectLastCall(); preparedStatement.setString(6, search.getJsonData()); EasyMock.expectLastCall(); EasyMock.replay(preparedStatement); dao.updatePreparedStatementForCreate(preparedStatement, search); EasyMock.verify(preparedStatement); }