Skip to content

Commit

Permalink
Add spring-shell-starter-test if Spring Shell is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
dashaun authored and odrotbohm committed May 27, 2024
1 parent 8be3c6e commit d5ccae0
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.spring.start.site.extension.dependency.springsecurity.SpringSecurityRSocketBuildCustomizer;
import io.spring.start.site.extension.dependency.springsecurity.SpringSecurityTestBuildCustomizer;
import io.spring.start.site.extension.dependency.springsession.SpringSessionBuildCustomizer;
import io.spring.start.site.extension.dependency.springshell.SpringShellTestBuildCustomizer;
import io.spring.start.site.extension.dependency.thymeleaf.ThymeleafBuildCustomizer;

import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -115,4 +116,10 @@ public MyBatisTestBuildCustomizer mybatisTestBuildCustomizer() {
return new MyBatisTestBuildCustomizer();
}

@Bean
@ConditionalOnRequestedDependency("spring-shell")
public SpringShellTestBuildCustomizer springShellTestBuildCustomizer() {
return new SpringShellTestBuildCustomizer();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.springshell;

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.buildsystem.DependencyScope;
import io.spring.initializr.generator.spring.build.BuildCustomizer;

/**
* A {@link BuildCustomizer} that automatically adds {@code spring-shell-test} when Spring
* Shell is selected.
*
* @author DaShaun Carter
*/
public class SpringShellTestBuildCustomizer implements BuildCustomizer<Build> {

@Override
public void customize(Build build) {
build.dependencies()
.add("spring-shell-starter-test",
Dependency.withCoordinates("org.springframework.shell", "spring-shell-starter-test")
.scope(DependencyScope.TEST_COMPILE));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Extensions for generation of projects that depend on Spring Shell.
*/
package io.spring.start.site.extension.dependency.springshell;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.springshell;

import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link SpringShellTestBuildCustomizer}.
*
* @author DaShaun Carter
*/
class SpringShellTestBuildCustomizerTests extends AbstractExtensionTests {

@Test
void shellTestIsAddedWithSpringShell() {
ProjectRequest request = createProjectRequest("spring-shell");
BillOfMaterials bom = getBom("spring-shell", request.getBootVersion());
assertThat(mavenPom(request)).hasDependency(getDependency("spring-shell"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependency(springShellStarterTest())
.hasDependenciesSize(3)
.hasBom("org.springframework.shell", "spring-shell-dependencies", "${spring-shell.version}")
.hasBomsSize(1)
.hasProperty("spring-shell.version", bom.getVersion());
}

@Test
void shellTestIsNotAddedWithoutSpringShell() {
ProjectRequest request = createProjectRequest("web");
assertThat(mavenPom(request)).hasDependency(Dependency.createSpringBootStarter("web"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(2);
}

private static Dependency springShellStarterTest() {
Dependency dependency = Dependency.withId("spring-shell-starter-test", "org.springframework.shell",
"spring-shell-starter-test");
dependency.setScope(Dependency.SCOPE_TEST);
return dependency;
}

}

0 comments on commit d5ccae0

Please sign in to comment.