### Question:
DBPolicyManager extends DBManager<Policy> implements PolicyManager { @Override public final List<Policy> getPolicyList(final Class<? extends Policy> clazz) throws PolicyManagerException { LOGGER.debug("getting policy list"); try { return super.getList(clazz, Restrictions.isNull("archivedTime")); } 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 testGetPolicyList() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); final String[] names = {"Policy1", "Policy2", "Policy3"}; final Policy[] expectedPolicies = new Policy[names.length]; for (int i = 0; i < names.length; ++i) { expectedPolicies[i] = createPolicy(mgr, names[i]); } final List<Policy> policies = mgr.getPolicyList(Policy.class); Assert.assertEquals(policies.size(), expectedPolicies.length); for (int i = 0; i < expectedPolicies.length; ++i) { Assert.assertTrue(policies.contains(expectedPolicies[i])); } }
@Test public void testGetPolicyListNullClass() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); final String[] names = {"Policy1", "Policy2", "Policy3"}; final Policy[] expectedPolicies = new Policy[names.length]; for (int i = 0; i < names.length; ++i) { expectedPolicies[i] = createPolicy(mgr, names[i]); } final List<Policy> policies = mgr.getPolicyList(null); Assert.assertEquals(policies.size(), expectedPolicies.length); for (int i = 0; i < expectedPolicies.length; ++i) { Assert.assertTrue(policies.contains(expectedPolicies[i])); } }
@Test public void testGetPolicyListDifferentClass() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); final String[] names = {"Policy1", "Policy2", "Policy3"}; final Policy[] expectedPolicies = new Policy[names.length]; for (int i = 0; i < names.length; ++i) { expectedPolicies[i] = createPolicy(mgr, names[i]); } final List<Policy> policies = mgr.getPolicyList(TestPolicy.class); Assert.assertEquals(policies.size(), expectedPolicies.length); for (int i = 0; i < expectedPolicies.length; ++i) { Assert.assertTrue(policies.contains(expectedPolicies[i])); } }
@Test public void testGetPolicyListDifferentClassNoReturn() throws PolicyManagerException { final PolicyManager mgr = new DBPolicyManager(sessionFactory); final String[] names = {"Policy1", "Policy2", "Policy3"}; for (int i = 0; i < names.length; ++i) { createPolicy(mgr, names[i]); } final List<Policy> policies = mgr.getPolicyList(TestPolicy2.class); Assert.assertEquals(policies.size(), 0); }