@Test(description = "This test case tests handling PolicyComplianceException when checking policy compliance",
      dependsOnMethods = "testCheckPolicyComplianceThrowingProfileManagerDAOException",
      expectedExceptions = PolicyComplianceException.class)
public void testAddProfileThrowingPolicyComplianceException() throws Exception {

    Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection();
    PowerMockito.doAnswer(new Answer<Connection>() {
        int callCounter = 0;
        @Override
        public Connection answer(InvocationOnMock invocationOnMock) throws Throwable {
            if(callCounter > 0){
                Field currentConnectionField = PolicyManagementDAOFactory.class.getDeclaredField("currentConnection");
                currentConnectionField.setAccessible(true);
                ThreadLocal<Connection> threadLocal = new ThreadLocal<>();
                threadLocal.set(pair.first());
                currentConnectionField.set(null, threadLocal);
                throw new SQLException();
            }
            callCounter++;
            return pair.second().first().getConnection();
        }
    }).when(pair.second().second()).getConnection();
    DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
    deviceIdentifier.setType(DEVICE_TYPE_E);
    deviceIdentifier.setId(String.valueOf(device5.getDeviceIdentifier()));
    try {
        monitoringManager.checkPolicyCompliance(deviceIdentifier, new ArrayList<ComplianceFeature>());
    } finally {
        PolicyManagementDAOFactory.init(pair.second().first());
    }
}