mirror of
https://gitee.com/dcren/initializr.git
synced 2025-05-05 21:28:03 +08:00
Polish "Create a settings.gradle file for Gradle projects"
Closes gh-643
This commit is contained in:
parent
aa75b1efaa
commit
5fef28a763
@ -1 +1 @@
|
||||
rootProject.name = '{{artifactId}}'
|
||||
rootProject.name = '{{artifactId}}'
|
||||
|
@ -70,6 +70,18 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
verifyProjectSuccessfulEventFor(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultProjectWithGradle() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.setType("gradle-build");
|
||||
ProjectAssert gradleProject = generateProject(request).isGradleProject();
|
||||
gradleProject.gradleBuildAssert()
|
||||
.contains("compile('org.springframework.boot:spring-boot-starter-web')")
|
||||
.contains("testCompile('org.springframework.boot:spring-boot-starter-test')");
|
||||
gradleProject.gradleSettingsAssert().hasProjectName("demo");
|
||||
verifyProjectSuccessfulEventFor(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDependencyAddsRootStarter() {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
@ -230,6 +242,16 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
.contains("package org.acme.foo145;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gradleProjectWithCustomArtifactId() {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
request.setType("gradle-build");
|
||||
request.setArtifactId("my-application");
|
||||
generateProject(request).isGradleProject().gradleSettingsAssert()
|
||||
.hasProjectName("my-application");
|
||||
verifyProjectSuccessfulEventFor(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springBoot11UseEnableAutoConfigurationJava() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2012-2018 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
|
||||
*
|
||||
* http://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.initializr.test.generator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Very simple assertions for the gradle settings.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class GradleSettingsAssert {
|
||||
|
||||
private final String content;
|
||||
|
||||
public GradleSettingsAssert(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public GradleSettingsAssert hasProjectName(String name) {
|
||||
return contains(String.format("rootProject.name = '%s'", name));
|
||||
}
|
||||
|
||||
public GradleSettingsAssert contains(String expression) {
|
||||
assertThat(this.content).contains(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@ -104,6 +104,19 @@ public class ProjectAssert {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link GradleSettingsAssert} for this project.
|
||||
*/
|
||||
public GradleSettingsAssert gradleSettingsAssert() {
|
||||
try {
|
||||
return new GradleSettingsAssert(StreamUtils.copyToString(
|
||||
new FileInputStream(file("settings.gradle")), Charset.forName("UTF-8")));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalArgumentException("Cannot resolve settings.gradle", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link SourceCodeAssert} for the specified source code.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user