Skip to content

Commit cab5337

Browse files
committed
Adding DirtiesContext
1 parent 7e5cc22 commit cab5337

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

chapter-4/chapter-4-spring-data-r2dbc/src/test/java/org/acme/TestContainerBase.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import org.testcontainers.junit.jupiter.Container;
55
import org.testcontainers.junit.jupiter.Testcontainers;
66

7+
import org.springframework.test.annotation.DirtiesContext;
78
import org.springframework.test.context.DynamicPropertyRegistry;
89
import org.springframework.test.context.DynamicPropertySource;
910

1011
@Testcontainers
12+
@DirtiesContext
1113
public abstract class TestContainerBase {
1214
@Container
1315
static final PostgreSQLContainer<?> DB = new PostgreSQLContainer<>("postgres:13")
@@ -18,9 +20,12 @@ public abstract class TestContainerBase {
1820

1921
@DynamicPropertySource
2022
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
21-
registry.add("spring.r2dbc.url",
22-
() -> String.format("r2dbc:postgresql://%s:%d/%s", DB.getHost(), DB.getFirstMappedPort(), DB.getDatabaseName()));
23+
registry.add("spring.r2dbc.url", TestContainerBase::getDbUrl);
2324
registry.add("spring.r2dbc.username", DB::getUsername);
2425
registry.add("spring.r2dbc.password", DB::getPassword);
2526
}
27+
28+
private static String getDbUrl() {
29+
return String.format("r2dbc:postgresql://%s:%d/%s", DB.getHost(), DB.getFirstMappedPort(), DB.getDatabaseName());
30+
}
2631
}

0 commit comments

Comments
 (0)