|
16 | 16 |
|
17 | 17 | package io.zonky.test.db.flyway; |
18 | 18 |
|
19 | | -import com.google.common.collect.Iterables; |
20 | 19 | import com.google.common.collect.ObjectArrays; |
21 | 20 | import io.zonky.test.db.logging.EmbeddedDatabaseReporter; |
22 | 21 | import org.aopalliance.intercept.MethodInterceptor; |
|
39 | 38 | import org.springframework.core.annotation.AnnotationUtils; |
40 | 39 | import org.springframework.test.context.TestContext; |
41 | 40 | import org.springframework.util.ClassUtils; |
42 | | -import org.springframework.util.CollectionUtils; |
43 | 41 |
|
44 | 42 | import javax.sql.DataSource; |
45 | 43 | import java.lang.annotation.Annotation; |
@@ -221,20 +219,20 @@ protected static boolean isAppendable(Flyway flyway, FlywayTest annotation) thro |
221 | 219 |
|
222 | 220 | protected static MigrationVersion findFirstVersion(Flyway flyway, String... locations) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { |
223 | 221 | 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); |
229 | 227 | } |
230 | 228 |
|
231 | 229 | protected static MigrationVersion findLastVersion(Flyway flyway, String... locations) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { |
232 | 230 | 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); |
238 | 236 | } |
239 | 237 |
|
240 | 238 | protected static Collection<ResolvedMigration> resolveMigrations(Flyway flyway, String... locations) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { |
|
0 commit comments