|
| 1 | +/* |
| 2 | + * Copyright 2012 - present the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.spring.initializr.generator.spring.build; |
| 18 | + |
| 19 | +import io.spring.initializr.generator.buildsystem.Build; |
| 20 | +import io.spring.initializr.generator.buildsystem.DependencyScope; |
| 21 | +import io.spring.initializr.generator.buildsystem.maven.MavenBuild; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | + |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; |
| 25 | + |
| 26 | +/** |
| 27 | + * Tests for {@link DefaultTestStarterBuildCustomizer}. |
| 28 | + * |
| 29 | + * @author Moritz Halbritter |
| 30 | + */ |
| 31 | +class DefaultTestStarterBuildCustomizerTests { |
| 32 | + |
| 33 | + @Test |
| 34 | + void defaultTestStarterIsAddedOnEmptyBuild() { |
| 35 | + Build build = new MavenBuild(); |
| 36 | + new DefaultTestStarterBuildCustomizer().customize(build); |
| 37 | + assertThat(build.dependencies().ids()).containsOnly(DefaultTestStarterBuildCustomizer.STARTER_ID); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + void defaultTestStarterIsAddedIfNoneExists() { |
| 42 | + Build build = new MavenBuild(); |
| 43 | + build.dependencies().add("acme", "com.example", "acme", DependencyScope.COMPILE); |
| 44 | + new DefaultTestStarterBuildCustomizer().customize(build); |
| 45 | + assertThat(build.dependencies().ids()).containsOnly("acme", DefaultTestStarterBuildCustomizer.STARTER_ID); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + void defaultTestStarterIsAddedIfNoTestScopedStarterExists() { |
| 50 | + Build build = new MavenBuild(); |
| 51 | + build.dependencies() |
| 52 | + .add("kafka-test", "org.springframework.boot", "spring-boot-starter-kafka-test", DependencyScope.COMPILE); |
| 53 | + new DefaultTestStarterBuildCustomizer().customize(build); |
| 54 | + assertThat(build.dependencies().ids()).containsOnly("kafka-test", DefaultTestStarterBuildCustomizer.STARTER_ID); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + void defaultTestStarterIsNotAddedIfTestScopedStarterExists() { |
| 59 | + Build build = new MavenBuild(); |
| 60 | + build.dependencies() |
| 61 | + .add("kafka-test", "org.springframework.boot", "spring-boot-starter-kafka-test", |
| 62 | + DependencyScope.TEST_COMPILE); |
| 63 | + new DefaultTestStarterBuildCustomizer().customize(build); |
| 64 | + assertThat(build.dependencies().ids()).containsOnly("kafka-test"); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void defaultTestStarterIsNotAddedIfDefaultTestScopedStarterExists() { |
| 69 | + Build build = new MavenBuild(); |
| 70 | + build.dependencies() |
| 71 | + .add("test", "org.springframework.boot", "spring-boot-starter-test", DependencyScope.TEST_COMPILE); |
| 72 | + new DefaultTestStarterBuildCustomizer().customize(build); |
| 73 | + assertThat(build.dependencies().ids()).containsOnly("test"); |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments