### Question:
DbImaBaselineRecordManager extends DBManager<IMABaselineRecord> implements ImaBaselineRecordManager { @Override public IMABaselineRecord saveRecord(final IMABaselineRecord record) throws ImaBaselineRecordManagerException { LOGGER.debug("saving ima baseline record: {}", record); if (record == null || record.getBaseline() == null) { throw new ImaBaselineRecordManagerException("Record cannot be saved without setting" + " baseline."); } try { if (getRecord(record.getPath(), record.getHash(), (SimpleImaBaseline) record.getBaseline()) != null) { throw new ImaBaselineRecordManagerException("Record already exists."); } else { return super.save(record); } } catch (DBManagerException e) { throw new ImaBaselineRecordManagerException(e); } } DbImaBaselineRecordManager(final SessionFactory sessionFactory); @Override IMABaselineRecord saveRecord(final IMABaselineRecord record); @Override IMABaselineRecord getRecord(final long id); @Override IMABaselineRecord getRecord(final String path, final Digest hash,
            final SimpleImaBaseline baseline); @Override boolean deleteRecord(final Long id); @Override boolean deleteRecord(final IMABaselineRecord record); final Collection<T> iterateOverBaselineRecords(
            final QueryableRecordImaBaseline baseline,
            final Callback<IMABaselineRecord, T> callback);  }### Answer:
@Test(expectedExceptions = ImaBaselineRecordManagerException.class) public void testSaveTwice() throws ImaBaselineRecordManagerException { LOGGER.debug("testSaveTwice test started"); final ImaBaselineRecordManager mgr = new DbImaBaselineRecordManager(sessionFactory); final IMABaselineRecord record = new IMABaselineRecord(PATH, createDigest(HASH)); record.setBaselineForRecordManager(baseline); final IMABaselineRecord r2 = mgr.saveRecord(record); mgr.saveRecord(r2); }
@Test(expectedExceptions = ImaBaselineRecordManagerException.class) public void testSaveSameRecord() throws ImaBaselineRecordManagerException { LOGGER.debug("testSaveSameRecord test started"); final ImaBaselineRecordManager mgr = new DbImaBaselineRecordManager(sessionFactory); final IMABaselineRecord record = new IMABaselineRecord(PATH, createDigest(HASH), baseline); final IMABaselineRecord record2 = new IMABaselineRecord(PATH, createDigest(HASH), baseline); mgr.saveRecord(record); mgr.saveRecord(record2); }
@Test(expectedExceptions = ImaBaselineRecordManagerException.class) public void testSaveNullRecord() throws ImaBaselineRecordManagerException { LOGGER.debug("testSaveNullRecord test started"); final ImaBaselineRecordManager mgr = new DbImaBaselineRecordManager(sessionFactory); mgr.saveRecord(null); }
@Test(expectedExceptions = ImaBaselineRecordManagerException.class) public void testSaveRecordNullBaseline() throws ImaBaselineRecordManagerException { LOGGER.debug("testSaveRecordNullBaseline test started"); final ImaBaselineRecordManager mgr = new DbImaBaselineRecordManager(sessionFactory); final IMABaselineRecord record = new IMABaselineRecord(PATH, createDigest(HASH)); final IMABaselineRecord r2 = mgr.saveRecord(record); mgr.saveRecord(r2); Assert.fail("second save did not fail"); }
@Test public void testAddingRecordsWillAddToImaBaseline() throws ImaBaselineRecordManagerException, UnsupportedEncodingException { final BaselineManager mgr = new DBBaselineManager(sessionFactory); final ImaBaselineRecordManager recordMgr = new DbImaBaselineRecordManager(sessionFactory); recordMgr.saveRecord(new IMABaselineRecord(PATH, createDigest(HASH), baseline)); SimpleImaBaseline retrievedBaseline = (SimpleImaBaseline) mgr.getCompleteBaseline(baseline.getName()); Assert.assertEquals(retrievedBaseline.getBaselineRecords().size(), 1); IMABaselineRecord firstRecord = new ArrayList<>(retrievedBaseline.getBaselineRecords()) .get(0); Assert.assertEquals(firstRecord.getPath(), PATH); Assert.assertEquals(firstRecord.getHash(), createDigest(HASH)); }