### Question:
DBAlertManager extends DBManager<Alert> implements AlertManager { @Override public final List<Alert> getAlertsForBaseline(final Baseline baseline) throws AlertManagerException { LOGGER.debug(""); if (baseline == null) { throw new NullPointerException("baseline was null"); } List<Alert> alerts = new ArrayList<>(); Transaction tx = null; Session session = getFactory().getCurrentSession(); try { tx = session.beginTransaction(); Criteria criteria = session.createCriteria(Alert.class); criteria.add(Restrictions.eq("baselineId", baseline.getId())); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List list = criteria.list(); for (Object o : list) { if (o instanceof Alert) { alerts.add((Alert) o); } } tx.commit(); } catch (HibernateException e) { final String msg = "unable to query alerts table"; LOGGER.error(msg, e); if (tx != null) { LOGGER.debug("rolling back transaction"); tx.rollback(); } throw e; } return alerts; } DBAlertManager(final SessionFactory factory); @Override final Alert saveAlert(final Alert alert); @Override final List<Alert> updateAlerts(final List<Alert> alerts); @Override final List<Alert> getAlertList(); @Override @SuppressWarnings("checkstyle:parameternumber") final FilteredRecordsList<Alert> getOrderedAlertList(
            final String reportId, final String columnToOrder, final boolean ascending,
            final int firstResult, final int maxResults, final String search,
            final AlertListType listType,
            final Map<String, Boolean> searchableColumns, final Date beginDate, final Date endDate); @Override final Alert getAlert(final UUID id); @Override final List<Alert> getAlertsForPolicy(final Policy policy); @Override final List<Alert> getAlertsForBaseline(final Baseline baseline); @Override final long getTotalAlertsForBaseline(final Baseline baseline); @Override List<Alert> getTrustAlerts(final Device device, final Report integrityReport,
                                      final Criterion optionalCriterion); @Override final int getTrustAlertCount(final Device device, final Report integrityReport,
                                    final Criterion optionalCriterion); @Override final void resolveAlerts(final List<Alert> alerts); @Override final void resolveAlerts(final List<Alert> alerts, final String description); final int countUnresolvedAlerts(final Device device); final int countUnresolvedAlerts(final Device device, final AlertSource source); final int countUnresolvedDevices(final DeviceGroup deviceGroup);  }### Answer:
@Test public void testGetAlertsForBaseline() throws AlertManagerException { final String baselineName = "baselineWithAlerts"; final AlertManager mgr = new DBAlertManager(sessionFactory); final BaselineManager bMgr = new DBBaselineManager(sessionFactory); Baseline baseline = bMgr.saveBaseline(new SimpleImaBaseline(baselineName)); Alert alert = new Alert("Alert One"); alert.setBaselineIdsAndSeverity(Collections.singleton(baseline)); Alert alertTwo = new Alert("Alert Two"); alertTwo.setBaselineIdsAndSeverity(Collections.singleton(baseline)); Alert alertThree = new Alert("Alert Three"); mgr.saveAlert(alert); mgr.saveAlert(alertTwo); mgr.saveAlert(alertThree); Assert.assertEquals(mgr.getTotalAlertsForBaseline(baseline), 2); Assert.assertEquals(mgr.getAlertsForBaseline(baseline).size(), 2); }