Add JUnit 5 checkstyle rules

Add a rule to enforce JUnit 5 usage and conventions.

Closes gh-17093
This commit is contained in:
Phillip Webb 2019-06-10 16:03:37 -07:00
parent 2560b54f7c
commit b3d5cd538d
29 changed files with 130 additions and 156 deletions

View File

@ -24,7 +24,7 @@
</property>
</activation>
<properties>
<spring-javaformat.version>0.0.11</spring-javaformat.version>
<spring-javaformat.version>0.0.12</spring-javaformat.version>
<nohttp-checkstyle.version>0.0.1.RELEASE</nohttp-checkstyle.version>
</properties>
<build>

View File

@ -71,7 +71,6 @@ class CassandraDataAutoConfigurationIntegrationTests {
AutoConfigurationPackages.register(this.context, cityPackage);
this.context.register(CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class);
this.context.refresh();
CassandraSessionFactoryBean bean = this.context.getBean(CassandraSessionFactoryBean.class);
assertThat(bean.getSchemaAction()).isEqualTo(SchemaAction.NONE);
}

View File

@ -103,7 +103,7 @@ class ElasticsearchDataAutoConfigurationTests {
}
@Test
public void customReactiveRestTemplateShouldBeUsed() {
void customReactiveRestTemplateShouldBeUsed() {
this.contextRunner.withUserConfiguration(CustomReactiveRestTemplate.class)
.run((context) -> assertThat(context).getBeanNames(ReactiveElasticsearchTemplate.class).hasSize(1)
.contains("reactiveElasticsearchTemplate"));

View File

@ -42,7 +42,7 @@ class RSocketMessagingAutoConfigurationTests {
.withUserConfiguration(BaseConfiguration.class);
@Test
public void shouldCreateDefaultBeans() {
void shouldCreateDefaultBeans() {
this.contextRunner.run((context) -> {
assertThat(context).getBeans(MessageHandlerAcceptor.class).hasSize(1);
assertThat(context.getBean(MessageHandlerAcceptor.class).getRouteMatcher())

View File

@ -19,33 +19,24 @@ package org.springframework.boot.docs.test.autoconfigure.restdocs.restassured;
// tag::source[]
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;
import static org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.document;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureRestDocs
public class UserDocumentationTests {
@LocalServerPort
private int port;
@Autowired
private RequestSpecification documentationSpec;
class UserDocumentationTests {
@Test
public void listUsers() {
given(this.documentationSpec).filter(document("list-users")).when().port(this.port).get("/").then().assertThat()
void listUsers(@Autowired RequestSpecification documentationSpec, @LocalServerPort int port) {
given(documentationSpec).filter(document("list-users")).when().port(port).get("/").then().assertThat()
.statusCode(is(200));
}

View File

@ -17,27 +17,21 @@
package org.springframework.boot.docs.test.context;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.assertThat;
// tag::example[]
@ExtendWith(SpringExtension.class)
@SpringBootTest(args = "--app.test=one")
public class ApplicationArgumentsExampleTests {
@Autowired
private ApplicationArguments args;
class ApplicationArgumentsExampleTests {
@Test
public void applicationArgumentsPopulated() {
assertThat(this.args.getOptionNames()).containsOnly("app.test");
assertThat(this.args.getOptionValues("app.test")).containsOnly("one");
void applicationArgumentsPopulated(@Autowired ApplicationArguments args) {
assertThat(args.getOptionNames()).containsOnly("app.test");
assertThat(args.getOptionValues("app.test")).containsOnly("one");
}
}

View File

@ -19,29 +19,22 @@ package org.springframework.boot.docs.test.web;
// tag::test-mock-mvc[]
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
public class MockMvcExampleTests {
@Autowired
private MockMvc mvc;
class MockMvcExampleTests {
@Test
public void exampleTest() throws Exception {
this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Hello World"));
void exampleTest(MockMvc mvc) throws Exception {
mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Hello World"));
}
}

View File

@ -19,26 +19,19 @@ package org.springframework.boot.docs.test.web;
// tag::test-mock-web-test-client[]
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureWebTestClient
public class MockWebTestClientExampleTests {
@Autowired
private WebTestClient webClient;
class MockWebTestClientExampleTests {
@Test
public void exampleTest() {
this.webClient.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class)
.isEqualTo("Hello World");
void exampleTest(@Autowired WebTestClient webClient) {
webClient.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello World");
}
}

View File

@ -19,26 +19,20 @@ package org.springframework.boot.docs.test.web;
// tag::test-random-port[]
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class RandomPortTestRestTemplateExampleTests {
@Autowired
private TestRestTemplate restTemplate;
class RandomPortTestRestTemplateExampleTests {
@Test
public void exampleTest() {
String body = this.restTemplate.getForObject("/", String.class);
void exampleTest(@Autowired TestRestTemplate restTemplate) {
String body = restTemplate.getForObject("/", String.class);
assertThat(body).isEqualTo("Hello World");
}

View File

@ -19,25 +19,18 @@ package org.springframework.boot.docs.test.web;
// tag::test-random-port[]
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class RandomPortWebTestClientExampleTests {
@Autowired
private WebTestClient webClient;
@Test
public void exampleTest() {
this.webClient.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class)
.isEqualTo("Hello World");
void exampleTest(@Autowired WebTestClient webClient) {
webClient.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello World");
}
}

View File

@ -37,6 +37,9 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
@RestClientTest(ExampleRestClient.class)
public class RestClientTestWithComponentIntegrationTests {
// JUnit 4 because RestClientTestWithoutJacksonIntegrationTests uses
// ModifiedClassPathRunner
@Autowired
private MockRestServiceServer server;

View File

@ -27,12 +27,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Brian Clozel
*/
public class CompoundConfigurationTableEntryTests {
class CompoundConfigurationTableEntryTests {
private static String NEWLINE = System.lineSeparator();
@Test
public void simpleProperty() {
void simpleProperty() {
ConfigurationMetadataProperty firstProp = new ConfigurationMetadataProperty();
firstProp.setId("spring.test.first");
firstProp.setType("java.lang.String");

View File

@ -27,12 +27,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Brian Clozel
*/
public class ConfigurationTableTests {
class ConfigurationTableTests {
private static String NEWLINE = System.lineSeparator();
@Test
public void simpleTable() {
void simpleTable() {
ConfigurationTable table = new ConfigurationTable("test");
ConfigurationMetadataProperty first = new ConfigurationMetadataProperty();
first.setId("spring.test.prop");

View File

@ -27,12 +27,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Brian Clozel
*/
public class SingleConfigurationTableEntryTests {
class SingleConfigurationTableEntryTests {
private static String NEWLINE = System.lineSeparator();
@Test
public void simpleProperty() {
void simpleProperty() {
ConfigurationMetadataProperty property = new ConfigurationMetadataProperty();
property.setId("spring.test.prop");
property.setDefaultValue("something");
@ -46,7 +46,7 @@ public class SingleConfigurationTableEntryTests {
}
@Test
public void noDefaultValue() {
void noDefaultValue() {
ConfigurationMetadataProperty property = new ConfigurationMetadataProperty();
property.setId("spring.test.prop");
property.setDescription("This is a description.");
@ -59,7 +59,7 @@ public class SingleConfigurationTableEntryTests {
}
@Test
public void defaultValueWithPipes() {
void defaultValueWithPipes() {
ConfigurationMetadataProperty property = new ConfigurationMetadataProperty();
property.setId("spring.test.prop");
property.setDefaultValue("first|second");
@ -73,7 +73,7 @@ public class SingleConfigurationTableEntryTests {
}
@Test
public void defaultValueWithBackslash() {
void defaultValueWithBackslash() {
ConfigurationMetadataProperty property = new ConfigurationMetadataProperty();
property.setId("spring.test.prop");
property.setDefaultValue("first\\second");
@ -87,7 +87,7 @@ public class SingleConfigurationTableEntryTests {
}
@Test
public void mapProperty() {
void mapProperty() {
ConfigurationMetadataProperty property = new ConfigurationMetadataProperty();
property.setId("spring.test.prop");
property.setDescription("This is a description.");
@ -100,7 +100,7 @@ public class SingleConfigurationTableEntryTests {
}
@Test
public void listProperty() {
void listProperty() {
String[] defaultValue = new String[] { "first", "second", "third" };
ConfigurationMetadataProperty property = new ConfigurationMetadataProperty();
property.setId("spring.test.prop");

View File

@ -38,12 +38,12 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson
*/
@ExtendWith(GradleBuildExtension.class)
public class BuildInfoDslIntegrationTests {
class BuildInfoDslIntegrationTests {
final GradleBuild gradleBuild = new GradleBuild();
@Test
public void basicJar() throws IOException {
void basicJar() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@ -54,7 +54,7 @@ public class BuildInfoDslIntegrationTests {
}
@Test
public void jarWithCustomName() throws IOException {
void jarWithCustomName() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@ -65,7 +65,7 @@ public class BuildInfoDslIntegrationTests {
}
@Test
public void basicWar() throws IOException {
void basicWar() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@ -76,7 +76,7 @@ public class BuildInfoDslIntegrationTests {
}
@Test
public void warWithCustomName() throws IOException {
void warWithCustomName() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@ -87,7 +87,7 @@ public class BuildInfoDslIntegrationTests {
}
@Test
public void additionalProperties() throws IOException {
void additionalProperties() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@ -100,7 +100,7 @@ public class BuildInfoDslIntegrationTests {
}
@Test
public void classesDependency() throws IOException {
void classesDependency() throws IOException {
assertThat(this.gradleBuild.build("classes", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
}

View File

@ -30,7 +30,12 @@ import org.springframework.boot.gradle.dsl.SpringBootExtension;
import static org.assertj.core.api.Assertions.assertThat;
public class MainClassConventionTests {
/**
* Integration tests for {@link MainClassConvention}.
*
* @author Andy Wilkinson
*/
class MainClassConventionTests {
@TempDir
File temp;
@ -40,20 +45,20 @@ public class MainClassConventionTests {
private MainClassConvention convention;
@BeforeEach
public void createConvention() throws IOException {
void createConvention() throws IOException {
this.project = ProjectBuilder.builder().withProjectDir(this.temp).build();
this.convention = new MainClassConvention(this.project, () -> null);
}
@Test
public void mainClassNameProjectPropertyIsUsed() throws Exception {
void mainClassNameProjectPropertyIsUsed() throws Exception {
this.project.getExtensions().getByType(ExtraPropertiesExtension.class).set("mainClassName",
"com.example.MainClass");
assertThat(this.convention.call()).isEqualTo("com.example.MainClass");
}
@Test
public void springBootExtensionMainClassNameIsUsed() throws Exception {
void springBootExtensionMainClassNameIsUsed() throws Exception {
SpringBootExtension extension = this.project.getExtensions().create("springBoot", SpringBootExtension.class,
this.project);
extension.setMainClassName("com.example.MainClass");
@ -61,7 +66,7 @@ public class MainClassConventionTests {
}
@Test
public void springBootExtensionMainClassNameIsUsedInPreferenceToMainClassNameProjectProperty() throws Exception {
void springBootExtensionMainClassNameIsUsedInPreferenceToMainClassNameProjectProperty() throws Exception {
this.project.getExtensions().getByType(ExtraPropertiesExtension.class).set("mainClassName",
"com.example.ProjectPropertyMainClass");
SpringBootExtension extension = this.project.getExtensions().create("springBoot", SpringBootExtension.class,

View File

@ -34,29 +34,29 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson
*/
@ExtendWith(GradleBuildExtension.class)
public class SpringBootPluginIntegrationTests {
class SpringBootPluginIntegrationTests {
final GradleBuild gradleBuild = new GradleBuild();
@Test
public void failFastWithVersionOfGradleLowerThanRequired() {
void failFastWithVersionOfGradleLowerThanRequired() {
BuildResult result = this.gradleBuild.gradleVersion("4.9").buildAndFail();
assertThat(result.getOutput())
.contains("Spring Boot plugin requires Gradle 4.10" + " or later. The current version is Gradle 4.9");
}
@Test
public void succeedWithVersionOfGradleHigherThanRequired() {
void succeedWithVersionOfGradleHigherThanRequired() {
this.gradleBuild.gradleVersion("4.10.1").build();
}
@Test
public void succeedWithVersionOfGradleMatchingWhatIsRequired() {
void succeedWithVersionOfGradleMatchingWhatIsRequired() {
this.gradleBuild.gradleVersion("4.10").build();
}
@Test
public void unresolvedDependenciesAreAnalyzedWhenDependencyResolutionFails() throws IOException {
void unresolvedDependenciesAreAnalyzedWhenDependencyResolutionFails() throws IOException {
createMinimalMainSource();
BuildResult result = this.gradleBuild.buildAndFail("compileJava");
assertThat(result.getOutput())

View File

@ -35,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
public class BuildInfoTests {
class BuildInfoTests {
@TempDir
File temp;
@Test
public void basicExecution() {
void basicExecution() {
Properties properties = buildInfoProperties(createTask(createProject("test")));
assertThat(properties).containsKey("build.time");
assertThat(properties).containsEntry("build.artifact", "unspecified");
@ -51,63 +51,63 @@ public class BuildInfoTests {
}
@Test
public void customArtifactIsReflectedInProperties() {
void customArtifactIsReflectedInProperties() {
BuildInfo task = createTask(createProject("test"));
task.getProperties().setArtifact("custom");
assertThat(buildInfoProperties(task)).containsEntry("build.artifact", "custom");
}
@Test
public void projectGroupIsReflectedInProperties() {
void projectGroupIsReflectedInProperties() {
BuildInfo task = createTask(createProject("test"));
task.getProject().setGroup("com.example");
assertThat(buildInfoProperties(task)).containsEntry("build.group", "com.example");
}
@Test
public void customGroupIsReflectedInProperties() {
void customGroupIsReflectedInProperties() {
BuildInfo task = createTask(createProject("test"));
task.getProperties().setGroup("com.example");
assertThat(buildInfoProperties(task)).containsEntry("build.group", "com.example");
}
@Test
public void customNameIsReflectedInProperties() {
void customNameIsReflectedInProperties() {
BuildInfo task = createTask(createProject("test"));
task.getProperties().setName("Example");
assertThat(buildInfoProperties(task)).containsEntry("build.name", "Example");
}
@Test
public void projectVersionIsReflectedInProperties() {
void projectVersionIsReflectedInProperties() {
BuildInfo task = createTask(createProject("test"));
task.getProject().setVersion("1.2.3");
assertThat(buildInfoProperties(task)).containsEntry("build.version", "1.2.3");
}
@Test
public void customVersionIsReflectedInProperties() {
void customVersionIsReflectedInProperties() {
BuildInfo task = createTask(createProject("test"));
task.getProperties().setVersion("2.3.4");
assertThat(buildInfoProperties(task)).containsEntry("build.version", "2.3.4");
}
@Test
public void timeIsSetInProperties() {
void timeIsSetInProperties() {
BuildInfo task = createTask(createProject("test"));
assertThat(buildInfoProperties(task)).containsEntry("build.time",
DateTimeFormatter.ISO_INSTANT.format(task.getProperties().getTime()));
}
@Test
public void timeCanBeRemovedFromProperties() {
void timeCanBeRemovedFromProperties() {
BuildInfo task = createTask(createProject("test"));
task.getProperties().setTime(null);
assertThat(buildInfoProperties(task)).doesNotContainKey("build.time");
}
@Test
public void timeCanBeCustomizedInProperties() {
void timeCanBeCustomizedInProperties() {
Instant now = Instant.now();
BuildInfo task = createTask(createProject("test"));
task.getProperties().setTime(now);
@ -115,7 +115,7 @@ public class BuildInfoTests {
}
@Test
public void additionalPropertiesAreReflectedInProperties() {
void additionalPropertiesAreReflectedInProperties() {
BuildInfo task = createTask(createProject("test"));
task.getProperties().getAdditional().put("a", "alpha");
task.getProperties().getAdditional().put("b", "bravo");

View File

@ -55,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @param <T> the type of the concrete BootArchive implementation
* @author Andy Wilkinson
*/
public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
@TempDir
File temp;
@ -80,7 +80,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@BeforeEach
public void createTask() {
void createTask() {
try {
File projectDir = new File(this.temp, "project");
projectDir.mkdirs();
@ -94,7 +94,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void basicArchiveCreation() throws IOException {
void basicArchiveCreation() throws IOException {
this.task.setMainClassName("com.example.Main");
executeTask();
assertThat(this.task.getArchivePath()).exists();
@ -109,7 +109,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void classpathJarsArePackagedBeneathLibPath() throws IOException {
void classpathJarsArePackagedBeneathLibPath() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(jarFile("one.jar"), jarFile("two.jar"));
executeTask();
@ -120,7 +120,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
this.task.setMainClassName("com.example.Main");
File classpathFolder = new File(this.temp, "classes");
File applicationClass = new File(classpathFolder, "com/example/Application.class");
@ -134,7 +134,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void moduleInfoClassIsPackagedInTheRootOfTheArchive() throws IOException {
void moduleInfoClassIsPackagedInTheRootOfTheArchive() throws IOException {
this.task.setMainClassName("com.example.Main");
File classpathFolder = new File(this.temp, "classes");
File moduleInfoClass = new File(classpathFolder, "module-info.class");
@ -154,7 +154,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void classpathCanBeSetUsingAFileCollection() throws IOException {
void classpathCanBeSetUsingAFileCollection() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(jarFile("one.jar"));
this.task.setClasspath(this.task.getProject().files(jarFile("two.jar")));
@ -166,7 +166,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void classpathCanBeSetUsingAnObject() throws IOException {
void classpathCanBeSetUsingAnObject() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(jarFile("one.jar"));
this.task.setClasspath(jarFile("two.jar"));
@ -178,7 +178,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void filesOnTheClasspathThatAreNotZipFilesAreSkipped() throws IOException {
void filesOnTheClasspathThatAreNotZipFilesAreSkipped() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(new File("test.pom"));
this.task.execute();
@ -188,7 +188,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void loaderIsWrittenToTheRootOfTheJar() throws IOException {
void loaderIsWrittenToTheRootOfTheJar() throws IOException {
this.task.setMainClassName("com.example.Main");
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
@ -198,7 +198,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher() throws IOException {
void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher() throws IOException {
this.task.setMainClassName("com.example.Main");
executeTask();
this.task.getManifest().getAttributes().put("Main-Class", "org.springframework.boot.loader.PropertiesLauncher");
@ -209,7 +209,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void unpackCommentIsAddedToEntryIdentifiedByAPattern() throws IOException {
void unpackCommentIsAddedToEntryIdentifiedByAPattern() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(jarFile("one.jar"), jarFile("two.jar"));
this.task.requiresUnpack("**/one.jar");
@ -221,7 +221,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void unpackCommentIsAddedToEntryIdentifiedByASpec() throws IOException {
void unpackCommentIsAddedToEntryIdentifiedByASpec() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(jarFile("one.jar"), jarFile("two.jar"));
this.task.requiresUnpack((element) -> element.getName().endsWith("two.jar"));
@ -233,7 +233,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void launchScriptCanBePrepended() throws IOException {
void launchScriptCanBePrepended() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.launchScript();
executeTask();
@ -253,7 +253,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void customLaunchScriptCanBePrepended() throws IOException {
void customLaunchScriptCanBePrepended() throws IOException {
this.task.setMainClassName("com.example.Main");
File customScript = new File(this.temp, "custom.script");
Files.write(customScript.toPath(), Arrays.asList("custom script"), StandardOpenOption.CREATE);
@ -263,7 +263,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void launchScriptInitInfoPropertiesCanBeCustomized() throws IOException {
void launchScriptInitInfoPropertiesCanBeCustomized() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.launchScript((configuration) -> {
configuration.getProperties().put("initInfoProvides", "provides");
@ -278,7 +278,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void customMainClassInTheManifestIsHonored() throws IOException {
void customMainClassInTheManifestIsHonored() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.getManifest().getAttributes().put("Main-Class", "com.example.CustomLauncher");
executeTask();
@ -292,7 +292,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void customStartClassInTheManifestIsHonored() throws IOException {
void customStartClassInTheManifestIsHonored() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.getManifest().getAttributes().put("Start-Class", "com.example.CustomMain");
executeTask();
@ -305,7 +305,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void fileTimestampPreservationCanBeDisabled() throws IOException {
void fileTimestampPreservationCanBeDisabled() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.setPreserveFileTimestamps(false);
executeTask();
@ -320,7 +320,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void reproducibleOrderingCanBeEnabled() throws IOException {
void reproducibleOrderingCanBeEnabled() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.from(newFile("bravo.txt"), newFile("alpha.txt"), newFile("charlie.txt"));
this.task.setReproducibleFileOrder(true);
@ -340,7 +340,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void devtoolsJarIsExcludedByDefault() throws IOException {
void devtoolsJarIsExcludedByDefault() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(newFile("spring-boot-devtools-0.1.2.jar"));
executeTask();
@ -351,7 +351,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void devtoolsJarCanBeIncluded() throws IOException {
void devtoolsJarCanBeIncluded() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(jarFile("spring-boot-devtools-0.1.2.jar"));
this.task.setExcludeDevtools(false);
@ -363,7 +363,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.setMetadataCharset("UTF-8");
File classpathFolder = new File(this.temp, "classes");
@ -384,7 +384,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries() throws IOException {
void loaderIsWrittenFirstThenApplicationClassesThenLibraries() throws IOException {
this.task.setMainClassName("com.example.Main");
File classpathFolder = new File(this.temp, "classes");
File applicationClass = new File(classpathFolder, "com/example/Application.class");

View File

@ -29,14 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
class BootJarTests extends AbstractBootArchiveTests<BootJar> {
public BootJarTests() {
BootJarTests() {
super(BootJar.class, "org.springframework.boot.loader.JarLauncher", "BOOT-INF/lib/", "BOOT-INF/classes/");
}
@Test
public void contentCanBeAddedToBootInfUsingCopySpecFromGetter() throws IOException {
void contentCanBeAddedToBootInfUsingCopySpecFromGetter() throws IOException {
BootJar bootJar = getTask();
bootJar.setMainClassName("com.example.Application");
bootJar.getBootInf().into("test").from(new File("build.gradle").getAbsolutePath());
@ -47,7 +47,7 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
}
@Test
public void contentCanBeAddedToBootInfUsingCopySpecAction() throws IOException {
void contentCanBeAddedToBootInfUsingCopySpecAction() throws IOException {
BootJar bootJar = getTask();
bootJar.setMainClassName("com.example.Application");
bootJar.bootInf((copySpec) -> copySpec.into("test").from(new File("build.gradle").getAbsolutePath()));

View File

@ -29,14 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
class BootWarTests extends AbstractBootArchiveTests<BootWar> {
public BootWarTests() {
BootWarTests() {
super(BootWar.class, "org.springframework.boot.loader.WarLauncher", "WEB-INF/lib/", "WEB-INF/classes/");
}
@Test
public void providedClasspathJarsArePackagedInWebInfLibProvided() throws IOException {
void providedClasspathJarsArePackagedInWebInfLibProvided() throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(jarFile("one.jar"), jarFile("two.jar"));
executeTask();
@ -47,7 +47,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
}
@Test
public void providedClasspathCanBeSetUsingAFileCollection() throws IOException {
void providedClasspathCanBeSetUsingAFileCollection() throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(jarFile("one.jar"));
getTask().setProvidedClasspath(getTask().getProject().files(jarFile("two.jar")));
@ -59,7 +59,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
}
@Test
public void providedClasspathCanBeSetUsingAnObject() throws IOException {
void providedClasspathCanBeSetUsingAnObject() throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(jarFile("one.jar"));
getTask().setProvidedClasspath(jarFile("two.jar"));
@ -71,7 +71,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
}
@Test
public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath() throws IOException {
void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath() throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(newFile("spring-boot-devtools-0.1.2.jar"));
executeTask();
@ -82,7 +82,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
}
@Test
public void devtoolsJarCanBeIncludedWhenItsOnTheProvidedClasspath() throws IOException {
void devtoolsJarCanBeIncludedWhenItsOnTheProvidedClasspath() throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(jarFile("spring-boot-devtools-0.1.2.jar"));
getTask().setExcludeDevtools(false);
@ -94,7 +94,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
}
@Test
public void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged() throws IOException {
void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged() throws IOException {
File webappFolder = new File(this.temp, "src/main/webapp");
webappFolder.mkdirs();
File orgFolder = new File(webappFolder, "org");
@ -111,7 +111,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
}
@Test
public void libProvidedEntriesAreWrittenAfterLibEntries() throws IOException {
void libProvidedEntriesAreWrittenAfterLibEntries() throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().classpath(jarFile("library.jar"));
getTask().providedClasspath(jarFile("provided-library.jar"));

View File

@ -30,7 +30,7 @@ import static org.mockito.Mockito.mock;
*
* @author Andy Wilkinson
*/
public class LaunchScriptConfigurationTests {
class LaunchScriptConfigurationTests {
private final AbstractArchiveTask task = mock(AbstractArchiveTask.class);
@ -42,49 +42,49 @@ public class LaunchScriptConfigurationTests {
}
@Test
public void initInfoProvidesUsesArchiveBaseNameByDefault() {
void initInfoProvidesUsesArchiveBaseNameByDefault() {
given(this.task.getBaseName()).willReturn("base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoProvides",
"base-name");
}
@Test
public void initInfoShortDescriptionUsesDescriptionByDefault() {
void initInfoShortDescriptionUsesDescriptionByDefault() {
given(this.project.getDescription()).willReturn("Project description");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
"Project description");
}
@Test
public void initInfoShortDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
void initInfoShortDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
given(this.task.getBaseName()).willReturn("base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
"base-name");
}
@Test
public void initInfoShortDescriptionUsesSingleLineVersionOfMultiLineProjectDescription() {
void initInfoShortDescriptionUsesSingleLineVersionOfMultiLineProjectDescription() {
given(this.project.getDescription()).willReturn("Project\ndescription");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
"Project description");
}
@Test
public void initInfoDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
void initInfoDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
given(this.task.getBaseName()).willReturn("base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
"base-name");
}
@Test
public void initInfoDescriptionUsesProjectDescriptionByDefault() {
void initInfoDescriptionUsesProjectDescriptionByDefault() {
given(this.project.getDescription()).willReturn("Project description");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
"Project description");
}
@Test
public void initInfoDescriptionUsesCorrectlyFormattedMultiLineProjectDescription() {
void initInfoDescriptionUsesCorrectlyFormattedMultiLineProjectDescription() {
given(this.project.getDescription()).willReturn("The\nproject\ndescription");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
"The\n# project\n# description");

View File

@ -49,7 +49,7 @@ public abstract class AbstractConfigurationClassTests {
private ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
@Test
public void allBeanMethodsArePublic() throws IOException {
void allBeanMethodsArePublic() throws IOException {
Set<String> nonPublicBeanMethods = new HashSet<>();
for (AnnotationMetadata configurationClass : findConfigurationClasses()) {
Set<MethodMetadata> beanMethods = configurationClass.getAnnotatedMethods(Bean.class.getName());

View File

@ -961,7 +961,7 @@ class ConfigFileApplicationListenerTests {
}
@Test
public void customDefaultPropertySourceIsNotReplaced() {
void customDefaultPropertySourceIsNotReplaced() {
// gh-17011
Map<String, Object> source = new HashMap<>();
source.put("mapkey", "mapvalue");

View File

@ -166,7 +166,7 @@ class SampleActuatorApplicationTests {
@Test
@SuppressWarnings("unchecked")
public void testBeans() {
void testBeans() {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
.getForEntity("/actuator/beans", Map.class);

View File

@ -58,7 +58,7 @@ class ShutdownSampleActuatorApplicationTests {
@Test
@DirtiesContext
public void testShutdown() {
void testShutdown() {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
.postForEntity("/actuator/shutdown", null, Map.class);

View File

@ -21,11 +21,10 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class Hibernate52ApplicationTests {
class Hibernate52ApplicationTests {
@Test
public void contextLoads() {
void contextLoads() {
}
}

View File

@ -38,4 +38,11 @@
<suppress files="SampleLogbackApplication\.java" checks="IllegalImport" />
<suppress files="FlywayAutoConfigurationTests\.java" checks="IllegalImport" />
<suppress files="JerseyAutoConfigurationServletContainerTests" checks="RedundantModifier" />
<suppress files="ModifiedClassPathRunnerOverridesTests" checks="SpringJUnit5" />
<suppress files="ModifiedClassPathRunnerExclusionsTests" checks="SpringJUnit5" />
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]org[\\/]springframework[\\/]boot[\\/]test[\\/]rule[\\/]" checks="SpringJUnit5" />
<suppress files="OutputCaptureRuleTests" checks="SpringJUnit5" />
<suppress files="JavaLoggingSystemTests" checks="SpringJUnit5" />
<suppress files="Log4J2LoggingSystemTests" checks="SpringJUnit5" />
<suppress files="RestClientTestWithComponentIntegrationTests" checks="SpringJUnit5" />
</suppressions>

View File

@ -8,6 +8,9 @@
</module>
<module name="io.spring.javaformat.checkstyle.SpringChecks" />
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">
<module name="io.spring.javaformat.checkstyle.check.SpringJUnit5Check">
<property name="unlessImports" value="org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner" />
</module>
<module
name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
<property name="regexp" value="true" />