### Question:
DBPolicyManager extends DBManager<Policy> implements PolicyManager { @Override public final Policy savePolicy(final Policy policy) throws PolicyManagerException { LOGGER.debug("saving policy: {}", policy); try { return super.save(policy); } 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 testSave() throws PolicyManagerException { final TestPolicy policy = new TestPolicy(POLICY_NAME); final PolicyManager mgr = new DBPolicyManager(sessionFactory); final TestPolicy p2 = (TestPolicy) mgr.savePolicy(policy); Assert.assertEquals(p2, policy); Assert.assertTrue(isInDatabase(POLICY_NAME)); }
@Test(expectedExceptions = PolicyManagerException.class) public void testSaveTwice() throws PolicyManagerException { final TestPolicy policy = new TestPolicy(POLICY_NAME); final PolicyManager mgr = new DBPolicyManager(sessionFactory); final TestPolicy p2 = (TestPolicy) mgr.savePolicy(policy); mgr.savePolicy(p2); Assert.fail("second save did not fail"); }
@Test(expectedExceptions = PolicyManagerException.class) public void testSaveSameName() throws PolicyManagerException { final TestPolicy policy = new TestPolicy(POLICY_NAME); final TestPolicy policy2 = new TestPolicy(POLICY_NAME); final PolicyManager mgr = new DBPolicyManager(sessionFactory); final TestPolicy p2 = (TestPolicy) mgr.savePolicy(policy); Assert.assertNotNull(p2); mgr.savePolicy(policy2); Assert.fail("second save did not fail"); }
@Test(expectedExceptions = NullPointerException.class) public void testSaveNullPolicy() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); mgr.savePolicy(null); Assert.fail("save did not fail"); }