Skip to content

Commit a087334

Browse files
Add test for "migrate constructor binding for multimodule project" (#376)
Co-authored-by: Sandeep Nagaraj <[email protected]>
1 parent 40239ab commit a087334

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,27 @@ void migrateMultiModuleApplication() {
5050
verifyParentPomVersion();
5151
verifyYamlConfigurationUpdate();
5252
verifyPropertyConfigurationUpdate();
53+
verifyConstructorBindingRemoval();
5354
verifyEhCacheVersionIsUpgraded();
5455
}
5556

57+
private void verifyConstructorBindingRemoval() {
58+
String constructorBindingConfigClass = loadJavaFileFromSubmodule("spring-app/", "org.springboot.example.upgrade", "ConstructorBindingConfig");
59+
assertThat(constructorBindingConfigClass).isEqualTo("package org.springboot.example.upgrade;\n" +
60+
"\n" +
61+
"import org.springframework.boot.context.properties.ConfigurationProperties;\n" +
62+
"\n" +
63+
"@ConfigurationProperties(prefix = \"mail\")\n" +
64+
"public class ConstructorBindingConfig {\n" +
65+
" private String hostName;\n" +
66+
"\n" +
67+
" public ConstructorBindingConfig(String hostName) {\n" +
68+
" this.hostName = hostName;\n" +
69+
" }\n" +
70+
"}" +
71+
"\n");
72+
}
73+
5674
private void verifyYamlConfigurationUpdate() {
5775
String micrometerClass = loadFile(Path.of("spring-app/src/main/resources/application.yaml"));
5876
assertThat(micrometerClass).isEqualTo(
@@ -136,7 +154,6 @@ private void verifyPropertyConfigurationUpdate() {
136154
"spring.datasource.username=sa\n" +
137155
"spring.datasource.password=password\n" +
138156
"spring.jpa.database-platform=org.hibernate.dialect.H2Dialect\n");
139-
140157
}
141158

142159
private void verifyEhCacheVersionIsUpgraded() {

applications/spring-shell/src/test/java/org/springframework/sbm/IntegrationTestBaseClass.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,20 @@ protected void replaceFile(Path target, Path source) {
318318
}
319319
}
320320

321-
protected String loadJavaFile(String packageName, String className) {
321+
protected String loadJavaFileFromSubmodule(String submodulePath, String packageName, String className) {
322322
try {
323-
Path classPath = testDir.resolve("src/main/java").resolve(packageName.replace(".", "/"));
323+
Path classPath = testDir.resolve(submodulePath + "src/main/java").resolve(packageName.replace(".", "/"));
324324
Path classFile = classPath.resolve(className + ".java");
325325
return Files.readString(classFile);
326326
} catch (IOException e) {
327327
throw new RuntimeException(e);
328328
}
329329
}
330330

331+
protected String loadJavaFile(String packageName, String className) {
332+
return loadJavaFileFromSubmodule("", packageName, className);
333+
}
334+
331335
/**
332336
* Starts {@code image} as Docker container exposing {@code ports} and waiting for {@code httpEndpoint} to be available.
333337
*/

0 commit comments

Comments
 (0)