  @Test
  public void testSessionFactoryExceptionally() {

    StandardServiceRegistry serviceRegistry = getServiceRegistry();
    when(sources.getMetadataBuilder()).thenThrow(new RuntimeException());
    assertThrows(RuntimeException.class, () -> HibernateUtils.getSessionFactory(sources));
    assertTrue(((StandardServiceRegistryImpl) serviceRegistry).isActive());

    when(sources.getServiceRegistry()).thenReturn(serviceRegistry);
    assertThrows(RuntimeException.class, () -> HibernateUtils.getSessionFactory(sources));
    assertFalse(((StandardServiceRegistryImpl) serviceRegistry).isActive());

  }