Skip to content

Commit cc88627

Browse files
committed
#36 fix processing repeatable migrations
1 parent 8603bb4 commit cc88627

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/OptimizedFlywayTestExecutionListener.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package io.zonky.test.db.flyway;
1818

19-
import com.google.common.collect.Iterables;
2019
import com.google.common.collect.ObjectArrays;
2120
import io.zonky.test.db.logging.EmbeddedDatabaseReporter;
2221
import org.aopalliance.intercept.MethodInterceptor;
@@ -39,7 +38,6 @@
3938
import org.springframework.core.annotation.AnnotationUtils;
4039
import org.springframework.test.context.TestContext;
4140
import org.springframework.util.ClassUtils;
42-
import org.springframework.util.CollectionUtils;
4341

4442
import javax.sql.DataSource;
4543
import java.lang.annotation.Annotation;
@@ -221,20 +219,20 @@ protected static boolean isAppendable(Flyway flyway, FlywayTest annotation) thro
221219

222220
protected static MigrationVersion findFirstVersion(Flyway flyway, String... locations) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
223221
Collection<ResolvedMigration> migrations = resolveMigrations(flyway, locations);
224-
if (CollectionUtils.isEmpty(migrations)) {
225-
return MigrationVersion.EMPTY;
226-
} else {
227-
return Iterables.getFirst(migrations, null).getVersion();
228-
}
222+
return migrations.stream()
223+
.filter(migration -> migration.getVersion() != null)
224+
.findFirst()
225+
.map(ResolvedMigration::getVersion)
226+
.orElse(MigrationVersion.EMPTY);
229227
}
230228

231229
protected static MigrationVersion findLastVersion(Flyway flyway, String... locations) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
232230
Collection<ResolvedMigration> migrations = resolveMigrations(flyway, locations);
233-
if (CollectionUtils.isEmpty(migrations)) {
234-
return MigrationVersion.EMPTY;
235-
} else {
236-
return Iterables.getLast(migrations).getVersion();
237-
}
231+
return migrations.stream()
232+
.filter(migration -> migration.getVersion() != null)
233+
.reduce((first, second) -> second) // finds last item
234+
.map(ResolvedMigration::getVersion)
235+
.orElse(MigrationVersion.EMPTY);
238236
}
239237

240238
protected static Collection<ResolvedMigration> resolveMigrations(Flyway flyway, String... locations) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
create or replace view test.people as select id, first_name from test.person;

0 commit comments

Comments
 (0)