ElasticSearchMigration { public void migrate(Consumer<ElasticSearch> consumer) { var search = new ElasticSearchImpl(); try { search.hosts = hosts; search.initialize(); consumer.accept(search); } catch (Throwable e) { logger.error("failed to run migration", e); throw e; } finally { close(search); } } ElasticSearchMigration(String propertyFileClasspath); void migrate(Consumer<ElasticSearch> consumer);  }
@Test void migrate() { assertThatThrownBy(() -> migration.migrate(search -> { throw new RuntimeException("migration error"); })).isInstanceOf(RuntimeException.class) .hasMessageContaining("migration"); }