### Question:
DBPolicyManager extends DBManager<Policy> implements PolicyManager { @Override public final Policy getPolicy(final String name) throws PolicyManagerException { LOGGER.debug("getting policy by name: {}", name); try { return super.get(name); } catch (DBManagerException e) { throw new PolicyManagerException(e); } } DBPolicyManager(final SessionFactory factory); @Override final Policy savePolicy(final Policy policy); @Override final void updatePolicy(final Policy policy); @Override final List<Policy> getPolicyList(final Class<? extends Policy> clazz); @Override List<Policy> getPoliciesContainingBaseline(
            final Class<? extends Policy> clazz,
            final Baseline baseline
    ); @Override final Policy getPolicy(final String name); @Override final Policy getPolicy(final Serializable id); @Override final void setDefaultPolicy(final Appraiser appraiser,
            final Policy policy); @Override final Policy getCompletePolicy(final String name); @Override final Policy getDefaultPolicy(final Appraiser appraiser); @Override final Policy getPolicy(
            final Appraiser appraiser,
            final Device device); @Override final Policy getPolicy(final Appraiser appraiser,
            final DeviceGroup deviceGroup); @Override final void setPolicy(final Appraiser appraiser,
            final DeviceGroup deviceGroup, final Policy policy); final int getGroupCountForPolicy(final Policy policy);  }### Answer:
@Test public void testGet() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); Assert.assertNull(mgr.getPolicy(POLICY_NAME)); final Policy policy = createPolicy(mgr); final Policy getPolicy = mgr.getPolicy(POLICY_NAME); Assert.assertNotNull(getPolicy); Assert.assertEquals(getPolicy, policy); Assert.assertEquals(getPolicy.getId(), policy.getId()); }
@Test public void testGetUnknown() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); Assert.assertNull(mgr.getPolicy("Some Unknown Policy")); }
@Test public void testGetNull() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); Assert.assertNull(mgr.getPolicy(null)); }
@Test public void testArchive() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); Assert.assertNull(mgr.getPolicy(POLICY_NAME)); createPolicy(mgr); Assert.assertNotNull(mgr.getPolicy(POLICY_NAME)); boolean archived = mgr.archive(POLICY_NAME); Assert.assertTrue(archived); Assert.assertTrue(mgr.getPolicy(POLICY_NAME).isArchived()); }
@Test public void testArchiveUnknown() throws PolicyManagerException { final String name = "Some unknown policy"; final PolicyManager mgr = new DBPolicyManager(sessionFactory); boolean archived = mgr.archive(name); Assert.assertFalse(archived); Assert.assertNull(mgr.getPolicy(POLICY_NAME)); }
@Test public void testGetPolicyNullAppraiser() throws Exception { final PolicyManager mgr = new DBPolicyManager(sessionFactory); DeviceGroup deviceGroup = createDeviceGroupWithDevice("Test Device Group", "Test Device"); final Policy policy = mgr.getPolicy(null, deviceGroup); Assert.assertNull(policy); }
@Test public void testGetPolicyNoneSet() throws Exception { final PolicyManager mgr = new DBPolicyManager(sessionFactory); DeviceGroup deviceGroup = createDeviceGroupWithDevice("Test Device Group", "Test Device"); final Policy policy = mgr.getPolicy(appraiser, deviceGroup); Assert.assertNull(policy); }