Skip to content

Commit 657c537

Browse files
committed
Add nullability annotations to tests in module/spring-boot-flyway
See gh-47263
1 parent 0753e7d commit 657c537

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

module/spring-boot-flyway/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,18 @@ dependencies {
5858
testImplementation("org.postgresql:postgresql")
5959
testImplementation("org.springframework:spring-orm")
6060

61+
testCompileOnly("org.checkerframework:checker-qual")
62+
6163
testRuntimeOnly("ch.qos.logback:logback-classic")
6264
testRuntimeOnly("com.h2database:h2")
6365
testRuntimeOnly("com.zaxxer:HikariCP")
6466
testRuntimeOnly("org.flywaydb:flyway-database-hsqldb")
6567
}
68+
69+
tasks.named("compileTestJava") {
70+
options.nullability.checking = "tests"
71+
}
72+
73+
tasks.named("compileDockerTestJava") {
74+
options.nullability.checking = "tests"
75+
}

module/spring-boot-flyway/src/test/java/org/springframework/boot/flyway/autoconfigure/FlywayAutoConfigurationTests.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.flywaydb.core.api.configuration.FluentConfiguration;
4444
import org.flywaydb.core.api.migration.JavaMigration;
4545
import org.flywaydb.core.api.pattern.ValidatePattern;
46+
import org.flywaydb.core.internal.configuration.models.ResolvedEnvironment;
4647
import org.flywaydb.core.internal.license.FlywayEditionUpgradeRequiredException;
4748
import org.flywaydb.database.oracle.OracleConfigurationExtension;
4849
import org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension;
@@ -393,7 +394,9 @@ void overrideDataSourceAndDriverClassName() {
393394
Flyway flyway = context.getBean(Flyway.class);
394395
SimpleDriverDataSource dataSource = (SimpleDriverDataSource) flyway.getConfiguration().getDataSource();
395396
assertThat(dataSource.getUrl()).isEqualTo(jdbcUrl);
396-
assertThat(dataSource.getDriver().getClass().getName()).isEqualTo(driverClassName);
397+
java.sql.Driver driver = dataSource.getDriver();
398+
assertThat(driver).isNotNull();
399+
assertThat(driver.getClass().getName()).isEqualTo(driverClassName);
397400
});
398401
}
399402

@@ -737,10 +740,11 @@ void jdbcPropertiesAreCorrectlyMapped() {
737740
.withPropertyValues("spring.flyway.jdbc-properties.prop=value")
738741
.run((context) -> {
739742
Flyway flyway = context.getBean(Flyway.class);
740-
assertThat(flyway.getConfiguration()
743+
ResolvedEnvironment environment = flyway.getConfiguration()
741744
.getCachedResolvedEnvironments()
742-
.get(flyway.getConfiguration().getCurrentEnvironmentName())
743-
.getJdbcProperties()).containsEntry("prop", "value");
745+
.get(flyway.getConfiguration().getCurrentEnvironmentName());
746+
assertThat(environment).isNotNull();
747+
assertThat(environment.getJdbcProperties()).containsEntry("prop", "value");
744748
});
745749
}
746750

@@ -1216,7 +1220,9 @@ static class PropertiesBackedH2DataSourceConfiguration extends AbstractUserH2Dat
12161220

12171221
@Override
12181222
protected String getDatabaseName(DataSourceProperties properties) {
1219-
return properties.determineDatabaseName();
1223+
String result = properties.determineDatabaseName();
1224+
assertThat(result).isNotNull();
1225+
return result;
12201226
}
12211227

12221228
}
@@ -1356,18 +1362,23 @@ public static class City implements Serializable {
13561362

13571363
@Id
13581364
@GeneratedValue
1365+
@SuppressWarnings("NullAway.Init")
13591366
private Long id;
13601367

13611368
@Column(nullable = false)
1369+
@SuppressWarnings("NullAway.Init")
13621370
private String name;
13631371

13641372
@Column(nullable = false)
1373+
@SuppressWarnings("NullAway.Init")
13651374
private String state;
13661375

13671376
@Column(nullable = false)
1377+
@SuppressWarnings("NullAway.Init")
13681378
private String country;
13691379

13701380
@Column(nullable = false)
1381+
@SuppressWarnings("NullAway.Init")
13711382
private String map;
13721383

13731384
protected City() {

module/spring-boot-flyway/src/test/java/org/springframework/boot/flyway/endpoint/FlywayEndpointTests.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.boot.autoconfigure.AutoConfigurations;
2424
import org.springframework.boot.flyway.autoconfigure.FlywayAutoConfiguration;
2525
import org.springframework.boot.flyway.autoconfigure.FlywayMigrationStrategy;
26+
import org.springframework.boot.flyway.endpoint.FlywayEndpoint.ContextFlywayBeansDescriptor;
2627
import org.springframework.boot.flyway.endpoint.FlywayEndpoint.FlywayDescriptor;
2728
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
2829
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -50,11 +51,12 @@ class FlywayEndpointTests {
5051
@Test
5152
void flywayReportIsProduced() {
5253
this.contextRunner.run((context) -> {
53-
Map<String, FlywayDescriptor> flywayBeans = context.getBean(FlywayEndpoint.class)
54+
ContextFlywayBeansDescriptor descriptor = context.getBean(FlywayEndpoint.class)
5455
.flywayBeans()
5556
.getContexts()
56-
.get(context.getId())
57-
.getFlywayBeans();
57+
.get(context.getId());
58+
assertThat(descriptor).isNotNull();
59+
Map<String, FlywayDescriptor> flywayBeans = descriptor.getFlywayBeans();
5860
assertThat(flywayBeans).hasSize(1);
5961
assertThat(flywayBeans.values().iterator().next().getMigrations()).hasSize(3);
6062
});
@@ -68,11 +70,12 @@ void whenFlywayHasBeenBaselinedFlywayReportIsProduced() {
6870
flyway.migrate();
6971
})
7072
.run((context) -> {
71-
Map<String, FlywayDescriptor> flywayBeans = context.getBean(FlywayEndpoint.class)
73+
ContextFlywayBeansDescriptor descriptor = context.getBean(FlywayEndpoint.class)
7274
.flywayBeans()
7375
.getContexts()
74-
.get(context.getId())
75-
.getFlywayBeans();
76+
.get(context.getId());
77+
assertThat(descriptor).isNotNull();
78+
Map<String, FlywayDescriptor> flywayBeans = descriptor.getFlywayBeans();
7679
assertThat(flywayBeans).hasSize(1);
7780
assertThat(flywayBeans.values().iterator().next().getMigrations()).hasSize(4);
7881
});

0 commit comments

Comments
 (0)