@@ -52,29 +52,30 @@ class MavenPomBuildConfigurationAdapterTest {
5252 private static final String BASE_PATH = "springboot/maven/java/" ;
5353
5454 private static ProjectBlueprint blueprint (
55- ArchitectureGovernance governance , Dependencies dependencies ) {
55+ ArchitectureGovernance governance , Dependencies dependencies , SampleCodeOptions sample ) {
56+
5657 ProjectMetadata metadata =
57- new ProjectMetadata (
58- new ProjectIdentity (new GroupId ("com.acme" ), new ArtifactId ("demo-app" )),
59- new ProjectName ("Demo App" ),
60- new ProjectDescription ("Sample Project" ),
61- new PackageName ("com.acme.demo" ));
58+ new ProjectMetadata (
59+ new ProjectIdentity (new GroupId ("com.acme" ), new ArtifactId ("demo-app" )),
60+ new ProjectName ("Demo App" ),
61+ new ProjectDescription ("Sample Project" ),
62+ new PackageName ("com.acme.demo" ));
6263
6364 TechStack techStack = new TechStack (Framework .SPRING_BOOT , BuildTool .MAVEN , Language .JAVA );
6465 PlatformTarget target = new SpringBootJvmTarget (JavaVersion .JAVA_21 , SpringBootVersion .V3_5 );
6566 PlatformSpec platform = new PlatformSpec (techStack , target );
6667
6768 ArchitectureSpec architecture =
68- new ArchitectureSpec (ProjectLayout .STANDARD , governance , SampleCodeOptions . none () );
69+ new ArchitectureSpec (ProjectLayout .STANDARD , governance , sample );
6970
7071 return ProjectBlueprint .of (metadata , platform , architecture , dependencies );
7172 }
7273
7374 private static Dependency dep (String groupId , String artifactId ) {
7475 return new Dependency (
75- new DependencyCoordinates (new GroupId (groupId ), new ArtifactId (artifactId )),
76- new DependencyVersion ("1.0.0" ),
77- DependencyScope .RUNTIME );
76+ new DependencyCoordinates (new GroupId (groupId ), new ArtifactId (artifactId )),
77+ new DependencyVersion ("1.0.0" ),
78+ DependencyScope .RUNTIME );
7879 }
7980
8081 @ Test
@@ -106,7 +107,8 @@ void generate_shouldBuildModel_withoutJpa_withoutGovernance() {
106107
107108 ProjectBlueprint bp =
108109 blueprint (
109- ArchitectureGovernance .none (), Dependencies .of (List .of (dep ("org.acme" , "custom-dep" ))));
110+ ArchitectureGovernance .none (),
111+ Dependencies .of (List .of (dep ("org.acme" , "custom-dep" ))), SampleCodeOptions .none ());
110112
111113 renderer .nextFile =
112114 new GeneratedTextResource (Path .of ("pom.xml" ), "<project/>" , StandardCharsets .UTF_8 );
@@ -139,6 +141,42 @@ void generate_shouldBuildModel_withoutJpa_withoutGovernance() {
139141 assertThat (deps .get (2 )).isEqualTo (MavenPomBuildModel .TEST_STARTER );
140142 }
141143
144+ @ Test
145+ @ DisplayName ("generate() should add WEB starter when sample code is enabled and web is not selected" )
146+ void generate_shouldAddWeb_whenSampleEnabled_andWebNotSelected () {
147+ CapturingTemplateRenderer renderer = new CapturingTemplateRenderer ();
148+
149+ List <BuildDependency > mapped =
150+ List .of (BuildDependency .of ("org.acme" , "custom-dep" , "1.0.0" , "runtime" ));
151+ RecordingBuildDependencyMapper mapper = new RecordingBuildDependencyMapper (mapped );
152+
153+ ArtifactSpec artifactSpec =
154+ new ArtifactSpec (BASE_PATH , List .of (new TemplateSpec ("pom.ftl" , "pom.xml" )));
155+ MavenPomBuildConfigurationAdapter adapter =
156+ new MavenPomBuildConfigurationAdapter (renderer , artifactSpec , mapper );
157+
158+ ProjectBlueprint bp =
159+ blueprint (
160+ ArchitectureGovernance .none (),
161+ Dependencies .of (List .of (dep ("org.acme" , "custom-dep" ))),
162+ SampleCodeOptions .basic ());
163+
164+ renderer .nextFile =
165+ new GeneratedTextResource (Path .of ("pom.xml" ), "<project/>" , StandardCharsets .UTF_8 );
166+
167+ adapter .generate (bp );
168+
169+ @ SuppressWarnings ("unchecked" )
170+ List <BuildDependency > deps =
171+ (List <BuildDependency >) renderer .capturedModel .get (MavenPomBuildModel .KEY_DEPENDENCIES );
172+
173+ assertThat (deps ).hasSize (4 );
174+ assertThat (deps .get (0 )).isEqualTo (MavenPomBuildModel .CORE_STARTER );
175+ assertThat (deps .get (1 )).isSameAs (mapped .getFirst ());
176+ assertThat (deps .get (2 )).isEqualTo (MavenPomBuildModel .WEB_STARTER );
177+ assertThat (deps .get (3 )).isEqualTo (MavenPomBuildModel .TEST_STARTER );
178+ }
179+
142180 @ Test
143181 @ DisplayName ("generate() should add H2 dependency when JPA starter is selected" )
144182 void generate_shouldAddH2_whenJpaSelected () {
@@ -164,7 +202,7 @@ void generate_shouldAddH2_whenJpaSelected() {
164202 ProjectBlueprint bp =
165203 blueprint (
166204 ArchitectureGovernance .none (),
167- Dependencies .of (List .of (dep ("org.acme" , "custom-dep" ), jpaStarter )));
205+ Dependencies .of (List .of (dep ("org.acme" , "custom-dep" ), jpaStarter )), SampleCodeOptions . none () );
168206
169207 renderer .nextFile =
170208 new GeneratedTextResource (Path .of ("pom.xml" ), "<project/>" , StandardCharsets .UTF_8 );
@@ -213,7 +251,7 @@ void generate_shouldAddArchUnit_whenGovernanceEnabled() {
213251 ProjectBlueprint bp =
214252 blueprint (
215253 ArchitectureGovernance .basic (),
216- Dependencies .of (List .of (dep ("org.acme" , "custom-dep" ), jpaStarter )));
254+ Dependencies .of (List .of (dep ("org.acme" , "custom-dep" ), jpaStarter )), SampleCodeOptions . none () );
217255
218256 renderer .nextFile =
219257 new GeneratedTextResource (Path .of ("pom.xml" ), "<project/>" , StandardCharsets .UTF_8 );
@@ -239,4 +277,5 @@ void generate_shouldAddArchUnit_whenGovernanceEnabled() {
239277 assertThat (deps .get (3 )).isEqualTo (MavenPomBuildModel .ARCH_UNIT_TEST );
240278 assertThat (deps .get (4 )).isEqualTo (MavenPomBuildModel .TEST_STARTER );
241279 }
280+
242281}
0 commit comments