### Question:
DBPolicyManager extends DBManager<Policy> implements PolicyManager { @Override public final void updatePolicy(final Policy policy) throws PolicyManagerException { LOGGER.debug("updating policy: {}", policy); try { super.update(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 testUpdate() throws PolicyManagerException { final String updatedName = "Updated Policy"; final PolicyManager mgr = new DBPolicyManager(sessionFactory); final Policy policy = createPolicy(mgr); policy.setName(updatedName); mgr.updatePolicy(policy); Assert.assertTrue(isInDatabase(updatedName)); Assert.assertFalse(isInDatabase(POLICY_NAME)); }
@Test public void testUpdateSameName() throws PolicyManagerException { final String name1 = "Test Policy 1"; final String name2 = "Test Policy 2"; final PolicyManager mgr = new DBPolicyManager(sessionFactory); createPolicy(mgr, name1); final Policy p2 = createPolicy(mgr, name2); p2.setName(name1); PolicyManagerException expected = null; try { mgr.updatePolicy(p2); } catch (PolicyManagerException e) { expected = e; } Assert.assertNotNull(expected); Assert.assertTrue(isInDatabase(name1)); Assert.assertTrue(isInDatabase(name2)); }
@Test(expectedExceptions = NullPointerException.class) public void testUpdateNullPolicy() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); mgr.updatePolicy(null); Assert.fail("save did not fail"); }