Skip to content

Commit 86e1837

Browse files
sanagaraj-pivotalfabapp2
authored andcommitted
Add Constructor Binding report
- defaultMap for shouldStartWith - Add javadoc to TestProjectContext
1 parent b214c0a commit 86e1837

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

components/sbm-core/src/test/java/org/springframework/sbm/project/resource/TestProjectContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ public Builder addJavaSource(Path sourcePathDir, String sourceCode) {
320320
return this;
321321
}
322322

323+
/**
324+
* Adds a Java source file to the {@code ProjectContext}.
325+
*
326+
* @param sourcePath e.g. {@code src/main/java} or {@code src/test/java} the package and classname are extracted from the given source code
327+
* @param sourceCode the source code of the java file. It will be used to calculate package and classname.
328+
*/
323329
public Builder addJavaSource(String sourcePath, String sourceCode) {
324330
return addJavaSource(Path.of(sourcePath), sourceCode);
325331
}

components/sbm-recipes-boot-upgrade/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
<artifactId>spring-asciidoctor-backends</artifactId>
6868
<version>${spring-asciidoctor-backends.version}</version>
6969
</dependency>
70+
<dependency>
71+
<groupId>org.openrewrite.recipe</groupId>
72+
<artifactId>rewrite-spring</artifactId>
73+
</dependency>
7074
<dependency>
7175
<groupId>org.springframework.boot</groupId>
7276
<artifactId>spring-boot-starter-test</artifactId>

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ConstructorBindingHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openrewrite.java.tree.J;
2525
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
2626
import org.springframework.sbm.engine.context.ProjectContext;
27+
import org.springframework.sbm.engine.recipe.OpenRewriteSourceFilesFinder;
2728
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
2829
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;
2930

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/ChangesToDataPropertiesReportTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ void changesToDataPropertiesSection_renders() {
4141
.fromProjectContext(context)
4242
.shouldRenderAs(
4343
"""
44-
=== Changes to Data Properties
45-
Issue: https://github.com/spring-projects-experimental/spring-boot-migrator/issues/441[#441], Contributors: https://github.com/fabapp2[@fabapp2^, role="ext-link"]
46-
47-
==== What Changed
48-
The data prefix has been reserved for Spring Data and any properties under the `data` prefix imply that Spring
49-
Data is required on the classpath.
50-
51-
==== Why is the application affected
52-
The scan found properties with `spring.data` prefix but no dependency matching `org.springframework.data:.*`.
53-
54-
* file://<PATH>/src/main/resources/application.properties[`src/main/resources/application.properties`]
55-
** `spring.data.foo`
56-
* file://<PATH>/src/main/resources/application-another.properties[`src/main/resources/application-another.properties`]
57-
** `spring.data.here`
58-
59-
==== Remediation
60-
Either add `spring-data` dependency, rename the property or remove it in case it's not required anymore.
61-
62-
""");
44+
=== Changes to Data Properties
45+
Issue: https://github.com/spring-projects-experimental/spring-boot-migrator/issues/441[#441], Contributors: https://github.com/fabapp2[@fabapp2^, role="ext-link"]
46+
47+
==== What Changed
48+
The data prefix has been reserved for Spring Data and any properties under the `data` prefix imply that Spring
49+
Data is required on the classpath.
50+
51+
==== Why is the application affected
52+
The scan found properties with `spring.data` prefix but no dependency matching `org.springframework.data:.*`.
53+
54+
* file://<PATH>/src/main/resources/application.properties[`src/main/resources/application.properties`]
55+
** `spring.data.foo`
56+
* file://<PATH>/src/main/resources/application-another.properties[`src/main/resources/application-another.properties`]
57+
** `spring.data.here`
58+
59+
==== Remediation
60+
Either add `spring-data` dependency, rename the property or remove it in case it's not required anymore.
61+
62+
""");
6363
}
6464

6565
@Test

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportTestSupport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void shouldNotRender() {
9191
}
9292

9393
public void shouldStartWith(String expectedOutput) {
94-
shouldStartWith(expectedOutput, Map.of());
94+
shouldStartWith(expectedOutput, defaultMap());
9595
}
9696

9797
public void shouldStartWith(String expectedOutput, Map<String, String> templateVariables) {
@@ -159,7 +159,6 @@ public void writeReport(String s, Path outputDir, String filename) {
159159
action.apply(reportBuilderData.getContext());
160160
});
161161
} else if(SectionBuilderData.class.isInstance(builderData)) {
162-
SectionBuilderData sectionBuilderData = SectionBuilderData.class.cast(builderData);
163162
withRecipes(recipes -> {
164163
Recipe recipe = recipes.getRecipeByName("boot-2.7-3.0-upgrade-report2").get();
165164
SpringBootUpgradeReportAction action = (SpringBootUpgradeReportAction) recipe.getActions().get(0);

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ConstructorBindingHelperTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.sbm.boot.upgrade_27_30.report.helper;
1818

1919
import org.intellij.lang.annotations.Language;
20-
import org.junit.jupiter.api.Disabled;
2120
import org.junit.jupiter.api.Test;
2221
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportTestSupport;
2322
import org.springframework.sbm.engine.context.ProjectContext;
@@ -64,10 +63,6 @@ public String getFrom() {
6463

6564
ProjectContext context = TestProjectContext.buildProjectContext()
6665
.addJavaSource("src/main/java", javaClassWithConstructorBinding)
67-
.addJavaSource("src/main/java", """
68-
package com.example;
69-
public class A {}
70-
""")
7166
.withBuildFileHavingDependencies("org.springframework.boot:spring-boot:2.7.1")
7267
.build();
7368

@@ -115,10 +110,5 @@ public class A { }
115110
.addJavaSource("src/main/java/com/example/A.java", javaClassWithConstructorBinding)
116111
.withBuildFileHavingDependencies("org.springframework.boot:spring-boot:2.7.1")
117112
.build();
118-
119-
SpringBootUpgradeReportTestSupport
120-
.generatedSection("Constructor Binding")
121-
.fromProjectContext(context)
122-
.shouldNotRender();
123113
}
124114
}

0 commit comments

Comments
 (0)