@Test
public void testRunDatabaseConsistencyCheck_ThrowException() throws Exception {

  EasyMockSupport easyMockSupport = new EasyMockSupport();
  final AmbariMetaInfo mockAmbariMetainfo = easyMockSupport.createNiceMock(AmbariMetaInfo.class);
  final DBAccessor mockDBDbAccessor = easyMockSupport.createNiceMock(DBAccessor.class);
  final OsFamily mockOSFamily = easyMockSupport.createNiceMock(OsFamily.class);
  final StackManagerFactory mockStackManagerFactory = easyMockSupport.createNiceMock(StackManagerFactory.class);
  final EntityManager mockEntityManager = easyMockSupport.createNiceMock(EntityManager.class);
  final Clusters mockClusters = easyMockSupport.createNiceMock(Clusters.class);
  AmbariServer ambariServer = new AmbariServer();
  final Configuration mockConfiguration = partialMockBuilder(Configuration.class).withConstructor()
      .addMockedMethod("getDatabaseType").createMock();
  final TypedQuery mockQuery = easyMockSupport.createNiceMock(TypedQuery.class);
  expect(mockConfiguration.getDatabaseType()).andReturn(null).anyTimes();
  expect(mockEntityManager.createNamedQuery(anyString(),anyObject(Class.class))).andReturn(mockQuery);
  expect(mockQuery.getResultList()).andReturn(new ArrayList());
  replay(mockConfiguration);
  final Injector mockInjector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(StackManagerFactory.class).toInstance(mockStackManagerFactory);
      bind(AmbariMetaInfo.class).toInstance(mockAmbariMetainfo);
      bind(DBAccessor.class).toInstance(mockDBDbAccessor);
      bind(OsFamily.class).toInstance(mockOSFamily);
      bind(EntityManager.class).toInstance(mockEntityManager);
      bind(Clusters.class).toInstance(mockClusters);
      bind(Configuration.class).toInstance(mockConfiguration);
    }
  });
  expect(mockDBDbAccessor.getConnection()).andReturn(null);
  DatabaseConsistencyCheckHelper.setInjector(mockInjector);
  easyMockSupport.replayAll();
  mockAmbariMetainfo.init();
  boolean errorOccurred = false;
  try {
    ambariServer.runDatabaseConsistencyCheck();
  } catch(Exception e) {
    errorOccurred = true;
  }
  junit.framework.Assert.assertTrue(errorOccurred);
  easyMockSupport.verifyAll();
}