Skip to content

Commit 3656fb0

Browse files
committed
Refactor tests #2
1 parent 92b44bc commit 3656fb0

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

spring-boot-2-demo-app/src/test/java/io/github/mfvanek/spring/boot2/test/IndexesMaintenanceTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
55
import io.github.mfvanek.pg.model.DbObject;
66
import io.github.mfvanek.pg.model.PgContext;
7-
import io.github.mfvanek.pg.model.column.Column;
7+
import io.github.mfvanek.pg.model.table.TableNameAware;
88
import io.github.mfvanek.spring.boot2.test.support.TestBase;
9-
import org.assertj.core.api.ListAssert;
109
import org.junit.jupiter.api.DisplayName;
1110
import org.junit.jupiter.api.Test;
1211
import org.springframework.beans.factory.annotation.Autowired;
1312

1413
import java.util.List;
14+
import java.util.function.Predicate;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17-
import static org.assertj.core.api.InstanceOfAssertFactories.list;
1817

1918
class IndexesMaintenanceTest extends TestBase {
2019

@@ -37,18 +36,16 @@ void databaseStructureCheckForPublicSchema() {
3736
checks.stream()
3837
.filter(DatabaseCheckOnHost::isStatic)
3938
.forEach(check -> {
40-
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), o -> !o.getName().equalsIgnoreCase("databasechangelog"));
41-
final ListAssert<? extends DbObject> checkAssert = assertThat(objects)
42-
.as(check.getDiagnostic().name());
43-
44-
if (check.getDiagnostic() == Diagnostic.COLUMNS_WITHOUT_DESCRIPTION) {
45-
assertThat(objects)
46-
.asInstanceOf(list(Column.class))
47-
.hasSize(14)
48-
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));
49-
} else {
50-
checkAssert.isEmpty();
51-
}
39+
final Predicate<DbObject> skipLiquibaseTables = dbObject -> {
40+
if (dbObject instanceof TableNameAware t) {
41+
return !t.getTableName().equalsIgnoreCase("databasechangelog");
42+
}
43+
return true;
44+
};
45+
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), skipLiquibaseTables);
46+
assertThat(objects)
47+
.as(check.getDiagnostic().name())
48+
.isEmpty();
5249
});
5350
}
5451
}

spring-boot-3-demo-app/src/test/java/io/github/mfvanek/spring/boot3/test/IndexesMaintenanceTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
55
import io.github.mfvanek.pg.model.DbObject;
66
import io.github.mfvanek.pg.model.PgContext;
7-
import io.github.mfvanek.pg.model.column.Column;
7+
import io.github.mfvanek.pg.model.table.TableNameAware;
88
import io.github.mfvanek.spring.boot3.test.support.TestBase;
9-
import org.assertj.core.api.ListAssert;
109
import org.junit.jupiter.api.DisplayName;
1110
import org.junit.jupiter.api.Test;
1211
import org.springframework.beans.factory.annotation.Autowired;
1312

1413
import java.util.List;
14+
import java.util.function.Predicate;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17-
import static org.assertj.core.api.InstanceOfAssertFactories.list;
1817

1918
class IndexesMaintenanceTest extends TestBase {
2019

@@ -37,18 +36,16 @@ void databaseStructureCheckForPublicSchema() {
3736
checks.stream()
3837
.filter(DatabaseCheckOnHost::isStatic)
3938
.forEach(check -> {
40-
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), o -> !o.getName().equalsIgnoreCase("databasechangelog"));
41-
final ListAssert<? extends DbObject> checkAssert = assertThat(objects)
42-
.as(check.getDiagnostic().name());
43-
44-
if (check.getDiagnostic() == Diagnostic.COLUMNS_WITHOUT_DESCRIPTION) {
45-
assertThat(objects)
46-
.asInstanceOf(list(Column.class))
47-
.hasSize(14)
48-
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));
49-
} else {
50-
checkAssert.isEmpty();
51-
}
39+
final Predicate<DbObject> skipLiquibaseTables = dbObject -> {
40+
if (dbObject instanceof TableNameAware t) {
41+
return !t.getTableName().equalsIgnoreCase("databasechangelog");
42+
}
43+
return true;
44+
};
45+
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), skipLiquibaseTables);
46+
assertThat(objects)
47+
.as(check.getDiagnostic().name())
48+
.isEmpty();
5249
});
5350
}
5451
}

0 commit comments

Comments
 (0)