MongoMigration { public void migrate(Consumer<Mongo> consumer) { var mongo = new MongoImpl(); try { mongo.uri = new ConnectionString(uri); mongo.initialize(); consumer.accept(mongo); } catch (Throwable e) { logger.error("failed to run migration", e); throw e; } finally { mongo.close(); } } MongoMigration(String propertyFileClasspath);  MongoMigration(String propertyFileClasspath, String key); void migrate(Consumer<Mongo> consumer);  }
@Test void migrate() { assertThatThrownBy(() -> migration.migrate(mongo -> { throw new RuntimeException("migration error"); })).isInstanceOf(RuntimeException.class) .hasMessageContaining("migration"); }