From 07bf731f47dbfa5e90bfdcacac49c6d3b107408f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 19 Feb 2019 11:18:42 +0000 Subject: [PATCH] Fix assertions of dependency scope, type, and version Closes gh-841 --- .../spring/test/build/PomAssert.java | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/test/build/PomAssert.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/test/build/PomAssert.java index e7b668fc..69de5cac 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/test/build/PomAssert.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/test/build/PomAssert.java @@ -165,7 +165,7 @@ public class PomAssert { /** * Assert {@code pom.xml} defines the specified starter. - * @param starterId the id of the starter (i.e. {@code web} for + * @param starterId the id of the starter (e.g. {@code web} for * {@code spring-boot-starter-web}. * @return this */ @@ -174,6 +174,18 @@ public class PomAssert { "spring-boot-starter-" + starterId); } + /** + * Assert {@code pom.xml} defines the specified starter in the specified scope. + * @param starterId the id of the starter (e.g. {@code web} for + * {@code spring-boot-starter-web}. + * @param scope the scope of the starter + * @return this + */ + public PomAssert hasSpringBootStarterDependency(String starterId, String scope) { + return hasDependency("org.springframework.boot", + "spring-boot-starter-" + starterId, null, scope); + } + /** * Assert {@code pom.xml} defines the root {@code spring-boot-starter} starter. * @return this @@ -187,7 +199,7 @@ public class PomAssert { * @return this */ public PomAssert hasSpringBootStarterTest() { - return hasSpringBootStarterDependency("test"); + return hasSpringBootStarterDependency("test", "test"); } /** @@ -212,6 +224,19 @@ public class PomAssert { return hasDependency(Dependency.create(groupId, artifactId, version, "compile")); } + /** + * Assert {@code pom.xml} defines the specified dependency with the specified scope. + * @param groupId the groupId of the dependency + * @param artifactId the artifactId of the dependency + * @param version the version of the dependency + * @param scope the scope of the dependency + * @return this + */ + public PomAssert hasDependency(String groupId, String artifactId, String version, + String scope) { + return hasDependency(Dependency.create(groupId, artifactId, version, scope)); + } + /** * Assert {@code pom.xml} defines the specified dependency. * @param dependency the dependency @@ -224,16 +249,15 @@ public class PomAssert { if (dependency.getGroupId().equals(actual.getGroupId()) && dependency .getArtifactId().equals(actual.getArtifactId())) { if (dependency.getVersion() != null) { - assertThat(dependency.getVersion()) + assertThat(actual.getVersion()) .isEqualTo(dependency.getVersion()); } if (dependency.getScope() != null) { - assertThat(dependency.getScope()) + assertThat(actual.getScope()) .isEqualTo(dependency.getScope()); } if (dependency.getType() != null) { - assertThat(dependency.getType()) - .isEqualTo(dependency.getType()); + assertThat(actual.getType()).isEqualTo(dependency.getType()); } return true; }