Upgrade to spring javaformat 0.0.38

This commit is contained in:
Stephane Nicoll
2023-04-03 14:57:51 +02:00
parent 32b5db7a5a
commit 5e97a01e99
207 changed files with 2449 additions and 1746 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* 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.
@@ -84,15 +84,17 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addBasicDefaults() {
return addDefaultTypes().addDefaultPackagings().addDefaultJavaVersions().addDefaultLanguages()
.addDefaultBootVersions();
return addDefaultTypes().addDefaultPackagings()
.addDefaultJavaVersions()
.addDefaultLanguages()
.addDefaultBootVersions();
}
public InitializrMetadataTestBuilder addDefaultTypes() {
return addType("maven-build", false, "/pom.xml", "maven", null, "build")
.addType("maven-project", true, "/starter.zip", "maven", null, "project")
.addType("gradle-build", false, "/build.gradle", "gradle", null, "build")
.addType("gradle-project", false, "/starter.zip", "gradle", null, "project");
.addType("maven-project", true, "/starter.zip", "maven", null, "project")
.addType("gradle-build", false, "/build.gradle", "gradle", null, "build")
.addType("gradle-project", false, "/starter.zip", "gradle", null, "project");
}
public InitializrMetadataTestBuilder addType(String id, boolean defaultValue, String action, String build,
@@ -166,7 +168,8 @@ public class InitializrMetadataTestBuilder {
public InitializrMetadataTestBuilder addDefaultBootVersions() {
return addBootVersion("2.2.17.RELEASE", false).addBootVersion("2.3.3.RELEASE", false)
.addBootVersion("2.4.1", true).addBootVersion("2.5.0-SNAPSHOT", false);
.addBootVersion("2.4.1", true)
.addBootVersion("2.5.0-SNAPSHOT", false);
}
public InitializrMetadataTestBuilder addBootVersion(String id, boolean defaultValue) {
@@ -206,8 +209,10 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder setGradleEnv(String dependencyManagementPluginVersion) {
this.builder.withCustomizer((it) -> it.getConfiguration().getEnv().getGradle()
.setDependencyManagementPluginVersion(dependencyManagementPluginVersion));
this.builder.withCustomizer((it) -> it.getConfiguration()
.getEnv()
.getGradle()
.setDependencyManagementPluginVersion(dependencyManagementPluginVersion));
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* 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.
@@ -63,7 +63,7 @@ public class MavenBuildAssert extends AbstractTextAssert<MavenBuildAssert> {
*/
public MavenBuildAssert hasParent(String groupId, String artifactId, String version) {
return hasText("/project/parent/groupId", groupId).hasText("/project/parent/artifactId", artifactId)
.hasText("/project/parent/version", version);
.hasText("/project/parent/version", version);
}
/**
@@ -248,12 +248,12 @@ public class MavenBuildAssert extends AbstractTextAssert<MavenBuildAssert> {
* @return {@code this} assertion object
*/
public MavenBuildAssert hasBom(String groupId, String artifactId, String version) {
this.pom.nodesAtPath("/project/dependencyManagement/dependencies/dependency").areExactly(1,
new Condition<>((candidate) -> {
BillOfMaterials actual = toBom(candidate);
return (actual != null && actual.getGroupId().equals(groupId)
&& actual.getArtifactId().equals(artifactId) && actual.getVersion().equals(version));
}, "matching bom"));
this.pom.nodesAtPath("/project/dependencyManagement/dependencies/dependency")
.areExactly(1, new Condition<>((candidate) -> {
BillOfMaterials actual = toBom(candidate);
return (actual != null && actual.getGroupId().equals(groupId)
&& actual.getArtifactId().equals(artifactId) && actual.getVersion().equals(version));
}, "matching bom"));
return this;
}
@@ -317,8 +317,8 @@ public class MavenBuildAssert extends AbstractTextAssert<MavenBuildAssert> {
* @return {@code this} assertion object
*/
public MavenBuildAssert hasProfile(String id) {
this.pom.nodesAtPath("/project/profiles/profile").areExactly(1,
new Condition<>(profile(id), "matching profile"));
this.pom.nodesAtPath("/project/profiles/profile")
.areExactly(1, new Condition<>(profile(id), "matching profile"));
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -73,7 +73,7 @@ public class NodeAssert extends AbstractAssert<NodeAssert, Node> implements Asse
private static Document read(String xmlContent) {
try {
return FACTORY.newDocumentBuilder()
.parse(new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8)));
.parse(new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8)));
}
catch (Exception ex) {
throw new RuntimeException(ex);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -130,8 +130,9 @@ public abstract class AbstractJvmModuleAssert<SELF extends AbstractJvmModuleAsse
private Path validateAndGetAsset(Path baseDir, String packageName, String name) {
Path source = resolveSource(baseDir, packageName, name);
new PathAssert(source)
.as("Source '%s.%s' not found in package '%s'", name, this.sourceFileExtension, packageName).exists()
.isRegularFile();
.as("Source '%s.%s' not found in package '%s'", name, this.sourceFileExtension, packageName)
.exists()
.isRegularFile();
return source;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -126,7 +126,7 @@ public abstract class AbstractProjectGenerationTester<SELF extends AbstractProje
private Consumer<ProjectGenerationContext> beansConfigurer() {
return (context) -> this.beanDefinitions
.forEach((type, definition) -> register(context, type, definition.get()));
.forEach((type, definition) -> register(context, type, definition.get()));
}
// Restore proper generic signature to make sure the context resolve the bean properly

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -119,9 +119,10 @@ public class ProjectAssetTester extends AbstractProjectGenerationTester<ProjectA
private ProjectAssetGenerator<ProjectStructure> runAllAvailableContributors() {
return (context) -> {
Path projectDirectory = context.getBean(ProjectDirectoryFactory.class)
.createProjectDirectory(context.getBean(ProjectDescription.class));
.createProjectDirectory(context.getBean(ProjectDescription.class));
List<ProjectContributor> projectContributors = context.getBeanProvider(ProjectContributor.class)
.orderedStream().collect(Collectors.toList());
.orderedStream()
.collect(Collectors.toList());
for (ProjectContributor projectContributor : projectContributors) {
projectContributor.contribute(projectDirectory);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -67,7 +67,7 @@ public class ProjectGeneratorTester extends AbstractProjectGenerationTester<Proj
public <T> T generate(MutableProjectDescription description, ProjectAssetGenerator<T> projectAssetGenerator) {
return invokeProjectGeneration(description, (contextInitializer) -> new ProjectGenerator(contextInitializer)
.generate(description, projectAssetGenerator));
.generate(description, projectAssetGenerator));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -49,13 +49,13 @@ class GroovyDslGradleBuildAssertTests {
@Test
void hasPluginWrongId() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasPlugin("com.another", "1.0.0.RELEASE"));
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasPlugin("com.another", "1.0.0.RELEASE"));
}
@Test
void hasPluginWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasPlugin("com.example", "2.0.0.RELEASE"));
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasPlugin("com.example", "2.0.0.RELEASE"));
}
@Test
@@ -66,7 +66,7 @@ class GroovyDslGradleBuildAssertTests {
@Test
void hasVersionWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasVersion("0.0.3-SNAPSHOT"));
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasVersion("0.0.3-SNAPSHOT"));
}
@Test
@@ -77,7 +77,7 @@ class GroovyDslGradleBuildAssertTests {
@Test
void hasSourceCompatibilityWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasSourceCompatibility("11"));
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasSourceCompatibility("11"));
}
@Test
@@ -88,7 +88,7 @@ class GroovyDslGradleBuildAssertTests {
@Test
void containsOnlyExtPropertiesWithExtraValue() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(forSampleGradleBuild())
.containsOnlyExtProperties("acmeVersion", "Brussels.SR2", "wrong", "1.0.0"));
.containsOnlyExtProperties("acmeVersion", "Brussels.SR2", "wrong", "1.0.0"));
}
private AssertProvider<GroovyDslGradleBuildAssert> forSampleGradleBuild() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -44,7 +44,7 @@ class GroovyDslGradleSettingsAssertTests {
@Test
void hasProjectNameWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleGradleSettings()).hasProjectName("another-project"));
.isThrownBy(() -> assertThat(forSampleGradleSettings()).hasProjectName("another-project"));
}
private AssertProvider<GroovyDslGradleSettingsAssert> forSampleGradleSettings() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* 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.
@@ -46,7 +46,7 @@ class MavenBuildAssertTests {
@Test
void hasParentWithWrongValue() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(forSampleMavenBuild())
.hasParent("com.example.wrong", "infrastructure-parent", "1.0.0.RELEASE"));
.hasParent("com.example.wrong", "infrastructure-parent", "1.0.0.RELEASE"));
}
@Test
@@ -57,7 +57,7 @@ class MavenBuildAssertTests {
@Test
void hasGroupIdWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasGroupId("com.wrong"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasGroupId("com.wrong"));
}
@Test
@@ -68,7 +68,7 @@ class MavenBuildAssertTests {
@Test
void hasArtifactIdWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasArtifactId("wrong"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasArtifactId("wrong"));
}
@Test
@@ -79,7 +79,7 @@ class MavenBuildAssertTests {
@Test
void hasVersionWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasVersion("1.0.0"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasVersion("1.0.0"));
}
@Test
@@ -90,7 +90,7 @@ class MavenBuildAssertTests {
@Test
void hasPackagingWithNoValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasPackaging("jar"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasPackaging("jar"));
}
@Test
@@ -101,7 +101,7 @@ class MavenBuildAssertTests {
@Test
void hasNameWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasName("wrong"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasName("wrong"));
}
@Test
@@ -112,7 +112,7 @@ class MavenBuildAssertTests {
@Test
void hasDescriptionWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDescription("Wrong description"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDescription("Wrong description"));
}
@Test
@@ -123,7 +123,7 @@ class MavenBuildAssertTests {
@Test
void hasPropertyWithWrongValue() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasProperty("acme.version", "Wrong.SR2"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasProperty("acme.version", "Wrong.SR2"));
}
@Test
@@ -134,7 +134,7 @@ class MavenBuildAssertTests {
@Test
void doesNotHavePropertyWithExistingProperty() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).doesNotHaveProperty("acme.version"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).doesNotHaveProperty("acme.version"));
}
@Test
@@ -145,7 +145,7 @@ class MavenBuildAssertTests {
@Test
void hasDependenciesSizeWithWrongSize() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDependenciesSize(3));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDependenciesSize(3));
}
@Test
@@ -156,7 +156,7 @@ class MavenBuildAssertTests {
@Test
void hasDependencyWithWrongScope() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDependency("com.example.acme", "library-test"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDependency("com.example.acme", "library-test"));
}
@Test
@@ -168,8 +168,8 @@ class MavenBuildAssertTests {
@Test
void hasDependencyWithVersionWithWrongVersion() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-dependency-version-pom.xml"))
.hasDependency("com.example.acme", "library", "1.3.0"));
.isThrownBy(() -> assertThat(forMavenBuild("sample-dependency-version-pom.xml"))
.hasDependency("com.example.acme", "library", "1.3.0"));
}
@Test
@@ -181,8 +181,8 @@ class MavenBuildAssertTests {
@Test
void hasDependencyWithVersionAndScopeWithWrongScope() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-dependency-version-pom.xml"))
.hasDependency("com.example.acme", "library-test", "1.3.0", "runtime"));
.isThrownBy(() -> assertThat(forMavenBuild("sample-dependency-version-pom.xml"))
.hasDependency("com.example.acme", "library-test", "1.3.0", "runtime"));
}
@Test
@@ -191,7 +191,7 @@ class MavenBuildAssertTests {
Dependency test = Dependency.withId("acme", "com.example.acme", "library", "1.2.0", "test");
test.setType("test-jar");
assertThat(forMavenBuild("sample-dependency-multiple-identical-gav-pom.xml")).hasDependency(main)
.hasDependency(test);
.hasDependency(test);
}
@Test
@@ -206,8 +206,8 @@ class MavenBuildAssertTests {
@Test
void doesNotHaveDependencyWithMatchingDependency() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(
() -> assertThat(forSampleMavenBuild()).doesNotHaveDependency("com.example.acme", "library"));
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).doesNotHaveDependency("com.example.acme", "library"));
}
@Test
@@ -218,7 +218,7 @@ class MavenBuildAssertTests {
@Test
void hasBomsSizeWithWrongSize() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasBomsSize(3));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasBomsSize(3));
}
@Test
@@ -257,7 +257,7 @@ class MavenBuildAssertTests {
@Test
void doesNotHaveBomWithMatchingBom() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forSampleMavenBuild()).doesNotHaveBom("com.example.acme", "library-bom"));
.isThrownBy(() -> assertThat(forSampleMavenBuild()).doesNotHaveBom("com.example.acme", "library-bom"));
}
@Test
@@ -273,7 +273,7 @@ class MavenBuildAssertTests {
@Test
void hasRepositoriesSizeWrongSize() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepositoriesSize(2));
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepositoriesSize(2));
}
@Test
@@ -291,37 +291,37 @@ class MavenBuildAssertTests {
@Test
void hasRepositoryWithWrongId() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-wrong",
"Acme Milestones", "https://repo.example.com/milestone", false));
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-wrong",
"Acme Milestones", "https://repo.example.com/milestone", false));
}
@Test
void hasRepositoryWithWrongName() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml"))
.hasRepository("acme-milestones", "Acme Wrong", "https://repo.example.com/milestone", false));
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-milestones",
"Acme Wrong", "https://repo.example.com/milestone", false));
}
@Test
void hasRepositoryWithWrongUrl() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(
() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-milestones",
"Acme Milestones", "https://repo.wrong.com/milestone", false));
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-milestones",
"Acme Milestones", "https://repo.wrong.com/milestone", false));
}
@Test
void hasRepositoryWithNullUrl() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-empty",
"Acme Empty", "https://repo.wrong.com/milestone", null))
.withMessageContaining("URL of repository acme-empty");
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-empty",
"Acme Empty", "https://repo.wrong.com/milestone", null))
.withMessageContaining("URL of repository acme-empty");
}
@Test
void hasRepositoryWithWrongSnapshotFlag() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(
() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-milestones",
"Acme Milestones", "https://repo.example.com/milestone", true));
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-milestones",
"Acme Milestones", "https://repo.example.com/milestone", true));
}
@Test
@@ -332,7 +332,7 @@ class MavenBuildAssertTests {
@Test
void hasProfileWithUnknownId() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forMavenBuild("sample-profiles-pom.xml")).hasProfile("unknown"));
.isThrownBy(() -> assertThat(forMavenBuild("sample-profiles-pom.xml")).hasProfile("unknown"));
}
private AssertProvider<MavenBuildAssert> forSampleMavenBuild() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -47,8 +47,8 @@ class TextAssertTests {
given(resource.isReadable()).willReturn(false);
given(resource.toString()).willReturn("project/does-not-exist");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forContent("Hello")).hasSameContentAs(resource))
.withMessageContaining("project/does-not-exist");
.isThrownBy(() -> assertThat(forContent("Hello")).hasSameContentAs(resource))
.withMessageContaining("project/does-not-exist");
}
@Test
@@ -57,8 +57,8 @@ class TextAssertTests {
given(resource.isReadable()).willReturn(true);
given(resource.getInputStream()).willThrow(new IOException("Test exception"));
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forContent("Hello")).hasSameContentAs(resource))
.withMessageContaining("Cannot read expected content");
.isThrownBy(() -> assertThat(forContent("Hello")).hasSameContentAs(resource))
.withMessageContaining("Cannot read expected content");
}
@Test
@@ -79,8 +79,9 @@ class TextAssertTests {
@Test
void sameContentAsWithNonMatchingResource() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forContent("Test")).hasSameContentAs(createResource("Hello")))
.withMessageContaining("Test").withMessageContaining("Hello");
.isThrownBy(() -> assertThat(forContent("Test")).hasSameContentAs(createResource("Hello")))
.withMessageContaining("Test")
.withMessageContaining("Hello");
}
@Test
@@ -99,8 +100,10 @@ class TextAssertTests {
writer.println("Test");
}
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forContent(file)).hasSameContentAs(createResource("Hello")))
.withMessageContaining("Test").withMessageContaining("Hello").withMessageContaining(file.toString());
.isThrownBy(() -> assertThat(forContent(file)).hasSameContentAs(createResource("Hello")))
.withMessageContaining("Test")
.withMessageContaining("Hello")
.withMessageContaining(file.toString());
}
private AssertProvider<TextAssert> forContent(String content) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* 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.
@@ -56,18 +56,16 @@ class JvmModuleAssertTests {
void hasMainSourceWithNonMatchingExtension(@TempDir Path root) throws IOException {
createFile(root, "src/main/java/com/example/Test.other");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainSource("com.example", "Test"))
.withMessageContaining(
String.format("Source '%s' not found in package '%s'", "Test.java", "com.example"));
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainSource("com.example", "Test"))
.withMessageContaining(String.format("Source '%s' not found in package '%s'", "Test.java", "com.example"));
}
@Test
void hasMainSourceWithNonMatchingSourceDir(@TempDir Path root) throws IOException {
createFile(root, "src/main/groovy/com/example/Test.java");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainSource("com.example", "Test"))
.withMessageContaining(
String.format("Source '%s' not found in package '%s'", "Test.java", "com.example"));
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainSource("com.example", "Test"))
.withMessageContaining(String.format("Source '%s' not found in package '%s'", "Test.java", "com.example"));
}
@Test
@@ -79,7 +77,7 @@ class JvmModuleAssertTests {
@Test
void mainSourceWithMissingSource(@TempDir Path root) {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forJavaProject(root)).mainSource("com.acme", "Test"));
.isThrownBy(() -> assertThat(forJavaProject(root)).mainSource("com.acme", "Test"));
}
@Test
@@ -91,7 +89,7 @@ class JvmModuleAssertTests {
@Test
void hasMainResourceWithMissingResource(@TempDir Path root) {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainResource("project/sample.xml"));
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainResource("project/sample.xml"));
}
@Test
@@ -110,18 +108,16 @@ class JvmModuleAssertTests {
void hasTestSourceWithNonMatchingExtension(@TempDir Path root) throws IOException {
createFile(root, "src/test/java/com/example/Test.other");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forJavaProject(root)).hasTestSource("com.example", "Test"))
.withMessageContaining(
String.format("Source '%s' not found in package '%s'", "Test.java", "com.example"));
.isThrownBy(() -> assertThat(forJavaProject(root)).hasTestSource("com.example", "Test"))
.withMessageContaining(String.format("Source '%s' not found in package '%s'", "Test.java", "com.example"));
}
@Test
void hasTestSourceWithNonMatchingSourceDir(@TempDir Path root) throws IOException {
createFile(root, "src/test/groovy/com/example/Test.java");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forJavaProject(root)).hasTestSource("com.example", "Test"))
.withMessageContaining(
String.format("Source '%s' not found in package '%s'", "Test.java", "com.example"));
.isThrownBy(() -> assertThat(forJavaProject(root)).hasTestSource("com.example", "Test"))
.withMessageContaining(String.format("Source '%s' not found in package '%s'", "Test.java", "com.example"));
}
@Test
@@ -133,7 +129,7 @@ class JvmModuleAssertTests {
@Test
void testSourceWithMissingSource(@TempDir Path root) {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forJavaProject(root)).testSource("com.acme", "DemoTests"));
.isThrownBy(() -> assertThat(forJavaProject(root)).testSource("com.acme", "DemoTests"));
}
private AssertProvider<AbstractJvmModuleAssert<?>> forJavaProject(Path root) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -50,7 +50,7 @@ class ModuleAssertTests {
void containDirectoriesWithMissingDirectory(@TempDir Path dir) throws IOException {
createDirectories(dir, "test", "test/another", "another");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).containsDirectories("test", "wrong"));
.isThrownBy(() -> assertThat(forDirectory(dir)).containsDirectories("test", "wrong"));
}
@Test
@@ -63,7 +63,7 @@ class ModuleAssertTests {
void doesNotContainDirectoriesWithExistingDirectory(@TempDir Path dir) throws IOException {
createDirectories(dir, "test", "test/another");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).doesNotContainDirectories("another", "test/another"));
.isThrownBy(() -> assertThat(forDirectory(dir)).doesNotContainDirectories("another", "test/another"));
}
@Test
@@ -76,7 +76,7 @@ class ModuleAssertTests {
void containFilesWithMissingFile(@TempDir Path dir) throws IOException {
createFiles(dir, "test.xml", "src/Test.java", "another");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).containsFiles("test.xml", "wrong"));
.isThrownBy(() -> assertThat(forDirectory(dir)).containsFiles("test.xml", "wrong"));
}
@Test
@@ -89,15 +89,15 @@ class ModuleAssertTests {
void doesNotContainFilesWithExistingFile(@TempDir Path dir) throws IOException {
createFiles(dir, "test.xml", "src/Test.java");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).doesNotContainFiles("another", "src/Test.java"));
.isThrownBy(() -> assertThat(forDirectory(dir)).doesNotContainFiles("another", "src/Test.java"));
}
@Test
void filePaths(@TempDir Path dir) throws IOException {
createFiles(dir, "src/One.java", "src/com/example/Two.java", "pom.xml", ".gitignore");
createDirectories(dir, "test/unrelated");
assertThat(forDirectory(dir)).filePaths().containsOnly("src/One.java", "src/com/example/Two.java", "pom.xml",
".gitignore");
assertThat(forDirectory(dir)).filePaths()
.containsOnly("src/One.java", "src/com/example/Two.java", "pom.xml", ".gitignore");
}
@Test
@@ -109,7 +109,7 @@ class ModuleAssertTests {
@Test
void fileWithMissingFile(@TempDir Path dir) {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).file("som/file/does-not-exist.txt"));
.isThrownBy(() -> assertThat(forDirectory(dir)).file("som/file/does-not-exist.txt"));
}
@Test
@@ -121,14 +121,15 @@ class ModuleAssertTests {
@Test
void textFileWithMissingFile(@TempDir Path dir) {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).textFile("som/file/does-not-exist.txt"));
.isThrownBy(() -> assertThat(forDirectory(dir)).textFile("som/file/does-not-exist.txt"));
}
@Test
void asJavaProject(@TempDir Path dir) throws IOException {
createFiles(dir, "src/main/java/com/example/Test.java");
assertThat(forDirectory(dir)).asJvmModule(new JavaLanguage()).hasMainPackage("com.example")
.hasMainSource("com.example", "Test");
assertThat(forDirectory(dir)).asJvmModule(new JavaLanguage())
.hasMainPackage("com.example")
.hasMainSource("com.example", "Test");
}
@Test
@@ -153,14 +154,14 @@ class ModuleAssertTests {
void hasMavenWrapperWithMissingScript(@TempDir Path dir) throws IOException {
createFiles(dir, ".mvn/wrapper/maven-wrapper.properties", ".mvn/wrapper/maven-wrapper.jar");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).hasMavenWrapper());
.isThrownBy(() -> assertThat(forDirectory(dir)).hasMavenWrapper());
}
@Test
void hasMavenWrapperWithMissingDotMvnDir(@TempDir Path dir) throws IOException {
createFiles(dir, "mvnw", "mvnw.cmd");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).hasMavenWrapper());
.isThrownBy(() -> assertThat(forDirectory(dir)).hasMavenWrapper());
}
@Test
@@ -184,7 +185,7 @@ class ModuleAssertTests {
void hasGroovyDslGradleBuildWithMissingBuildFile(@TempDir Path dir) throws IOException {
createFiles(dir, "build.wrong");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGroovyDslGradleBuild());
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGroovyDslGradleBuild());
}
@Test
@@ -198,14 +199,14 @@ class ModuleAssertTests {
void hasGradleWrapperWithMissingScript(@TempDir Path dir) throws IOException {
createFiles(dir, "gradle/wrapper/gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.jar");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGradleWrapper());
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGradleWrapper());
}
@Test
void hasGradleWrapperWithMissingGradleDir(@TempDir Path dir) throws IOException {
createFiles(dir, "gradlew", "gradlew.bat");
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGradleWrapper());
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGradleWrapper());
}
@Test
@@ -217,7 +218,7 @@ class ModuleAssertTests {
@Test
void groovyDslGradleBuildWithMissingBuildFile(@TempDir Path dir) {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(forDirectory(dir)).groovyDslGradleBuild());
.isThrownBy(() -> assertThat(forDirectory(dir)).groovyDslGradleBuild());
}
private AssertProvider<ModuleAssert> forDirectory(Path projectDirectory) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -49,8 +49,9 @@ class ProjectAssetTesterTests {
@Test
void testerWithIndentingWriterFactory() {
new ProjectAssetTester().withIndentingWriterFactory().configure(new MutableProjectDescription(),
(context) -> assertThat(context).hasSingleBean(IndentingWriterFactory.class));
new ProjectAssetTester().withIndentingWriterFactory()
.configure(new MutableProjectDescription(),
(context) -> assertThat(context).hasSingleBean(IndentingWriterFactory.class));
}
@Test
@@ -58,25 +59,26 @@ class ProjectAssetTesterTests {
MutableProjectDescription description = new MutableProjectDescription();
description.setName("test.text");
ProjectStructure project = new ProjectAssetTester().withDirectory(directory)
.withConfiguration(ContributorsConfiguration.class).generate(description);
.withConfiguration(ContributorsConfiguration.class)
.generate(description);
assertThat(project).filePaths().containsOnly("test.text", "test2.text");
}
@Test
void testerWithContextFailureIsProperlyReported() {
new ProjectAssetTester().withConfiguration(ContributorFailureConfiguration.class)
.configure(new MutableProjectDescription(), (context) -> {
assertThat(context).hasFailed();
assertThat(context.getStartupFailure()).isInstanceOf(UnsatisfiedDependencyException.class);
assertThat(context.getStartupFailure().getMessage()).doesNotContain("Should not be invoked");
});
.configure(new MutableProjectDescription(), (context) -> {
assertThat(context).hasFailed();
assertThat(context.getStartupFailure()).isInstanceOf(UnsatisfiedDependencyException.class);
assertThat(context.getStartupFailure().getMessage()).doesNotContain("Should not be invoked");
});
}
@Test
void testerWithContextSuccessFailToAssertFailure() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> new ProjectAssetTester().withConfiguration(ContributorsConfiguration.class)
.configure(new MutableProjectDescription(), (context) -> assertThat(context).hasFailed()));
.isThrownBy(() -> new ProjectAssetTester().withConfiguration(ContributorsConfiguration.class)
.configure(new MutableProjectDescription(), (context) -> assertThat(context).hasFailed()));
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* 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.
@@ -39,8 +39,8 @@ class ProjectGeneratorTesterTests {
@Test
void testerHasNoRegisteredContributorByDefault() {
Map<String, ProjectContributor> contributors = new ProjectGeneratorTester().generate(
new MutableProjectDescription(), (context) -> context.getBeansOfType(ProjectContributor.class));
Map<String, ProjectContributor> contributors = new ProjectGeneratorTester()
.generate(new MutableProjectDescription(), (context) -> context.getBeansOfType(ProjectContributor.class));
assertThat(contributors).isEmpty();
}
@@ -60,15 +60,15 @@ class ProjectGeneratorTesterTests {
@Test
void testerWithExplicitProjectContributors(@TempDir Path directory) {
ProjectGeneratorTester tester = new ProjectGeneratorTester().withDirectory(directory)
.withContextInitializer((context) -> {
context.registerBean("contributor1", ProjectContributor.class,
() -> (projectDirectory) -> Files.createFile(projectDirectory.resolve("test.text")));
context.registerBean("contributor2", ProjectContributor.class, () -> (projectDirectory) -> {
Path subDir = projectDirectory.resolve("src/main/test");
Files.createDirectories(subDir);
Files.createFile(subDir.resolve("Test.src"));
});
.withContextInitializer((context) -> {
context.registerBean("contributor1", ProjectContributor.class,
() -> (projectDirectory) -> Files.createFile(projectDirectory.resolve("test.text")));
context.registerBean("contributor2", ProjectContributor.class, () -> (projectDirectory) -> {
Path subDir = projectDirectory.resolve("src/main/test");
Files.createDirectories(subDir);
Files.createFile(subDir.resolve("Test.src"));
});
});
ProjectStructure project = tester.generate(new MutableProjectDescription());
assertThat(project).filePaths().containsOnly("test.text", "src/main/test/Test.src");
}