FeatureManagerImpl implements FeatureManager { @Override public List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException { try { PolicyManagementDAOFactory.openConnection(); return featureDAO.getAllFeatures(deviceType); } catch (FeatureManagerDAOException e) { throw new FeatureManagementException("Error occurred while retrieving the features", e); } catch (SQLException e) { throw new FeatureManagementException("Error occurred while opening a connection to the data source", e); } finally { PolicyManagementDAOFactory.closeConnection(); } } FeatureManagerImpl(); @Override ProfileFeature addProfileFeature(ProfileFeature feature, int profileId); @Override ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId); @Override List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId); @Override List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId); @Override List<Feature> getAllFeatures(String deviceType); @Override List<ProfileFeature> getFeaturesForProfile(int profileId); @Override boolean deleteFeaturesOfProfile(Profile profile);  }
@Test(description = "This test case tests retrieving all features of a device type", dependsOnMethods = "testUpdateProfileFeaturesThrowingIllegalTransactionStateException", expectedExceptions = FeatureManagementException.class) public void testGetAllFeatures() throws Exception { featureManager.getAllFeatures(DEVICE_TYPE_D); }
@Test(description = "This test case tests handling SQLException when all features of a device type", dependsOnMethods = "testGetAllFeatures", expectedExceptions = {IllegalTransactionStateException.class, FeatureManagementException.class}) public void testGetAllFeaturesThrowingIllegalTransactionStateException() throws Exception { Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection(); PowerMockito.doThrow(new SQLException()).when(pair.second().second()).getConnection(); try { featureManager.getAllFeatures(DEVICE_TYPE_D); } finally { PolicyManagementDAOFactory.init(pair.second().first()); } }