Merge branch '2.7.x' into 3.0.x

This commit is contained in:
Phillip Webb
2023-02-21 23:15:40 -08:00
1890 changed files with 27173 additions and 21952 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,25 +84,25 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
private void addConditionPropertyGenerators(List<PropertyGenerator> generators) {
String annotationPackage = "org.springframework.boot.autoconfigure.condition";
generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnClass")
.withAnnotation(new OnClassConditionValueExtractor()));
.withAnnotation(new OnClassConditionValueExtractor()));
generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnBean")
.withAnnotation(new OnBeanConditionValueExtractor()));
.withAnnotation(new OnBeanConditionValueExtractor()));
generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnSingleCandidate")
.withAnnotation(new OnBeanConditionValueExtractor()));
.withAnnotation(new OnBeanConditionValueExtractor()));
generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnWebApplication")
.withAnnotation(ValueExtractor.allFrom("type")));
.withAnnotation(ValueExtractor.allFrom("type")));
}
private void addAutoConfigurePropertyGenerators(List<PropertyGenerator> generators) {
String annotationPackage = "org.springframework.boot.autoconfigure";
generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureBefore", true)
.withAnnotation(ValueExtractor.allFrom("value", "name"))
.withAnnotation("AutoConfiguration", ValueExtractor.allFrom("before", "beforeName")));
.withAnnotation(ValueExtractor.allFrom("value", "name"))
.withAnnotation("AutoConfiguration", ValueExtractor.allFrom("before", "beforeName")));
generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureAfter", true)
.withAnnotation(ValueExtractor.allFrom("value", "name"))
.withAnnotation("AutoConfiguration", ValueExtractor.allFrom("after", "afterName")));
.withAnnotation(ValueExtractor.allFrom("value", "name"))
.withAnnotation("AutoConfiguration", ValueExtractor.allFrom("after", "afterName")));
generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureOrder")
.withAnnotation(ValueExtractor.allFrom("value")));
.withAnnotation(ValueExtractor.allFrom("value")));
}
@Override
@@ -207,7 +207,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
Object value = annotationValue.getValue();
if (value instanceof List) {
return ((List<AnnotationValue>) value).stream()
.map((annotation) -> extractValue(annotation.getValue()));
.map((annotation) -> extractValue(annotation.getValue()));
}
return Stream.of(extractValue(value));
}
@@ -248,7 +248,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
public List<Object> getValues(AnnotationMirror annotation) {
Map<String, AnnotationValue> attributes = new LinkedHashMap<>();
annotation.getElementValues()
.forEach((key, value) -> attributes.put(key.getSimpleName().toString(), value));
.forEach((key, value) -> attributes.put(key.getSimpleName().toString(), value));
if (attributes.containsKey("name")) {
return Collections.emptyList();
}
@@ -274,8 +274,9 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
}
private int compare(Object o1, Object o2) {
return Comparator.comparing(this::isSpringClass).thenComparing(String.CASE_INSENSITIVE_ORDER)
.compare(o1.toString(), o2.toString());
return Comparator.comparing(this::isSpringClass)
.thenComparing(String.CASE_INSENSITIVE_ORDER)
.compare(o1.toString(), o2.toString());
}
private boolean isSpringClass(String type) {

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.
@@ -47,9 +47,9 @@ class AutoConfigureAnnotationProcessorTests {
"java.io.InputStream,org.springframework.boot.autoconfigureprocessor."
+ "TestClassConfiguration$Nested,org.springframework.foo");
assertThat(properties)
.containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration");
.containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration");
assertThat(properties)
.containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration$Nested");
.containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration$Nested");
assertThat(properties).containsEntry(
"org.springframework.boot.autoconfigureprocessor.TestClassConfiguration.ConditionalOnBean",
"java.io.OutputStream");
@@ -156,7 +156,7 @@ class AutoConfigureAnnotationProcessorTests {
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor).withSources(sourceFile);
compiler.compile((compiled) -> {
InputStream propertiesFile = compiled.getClassLoader()
.getResourceAsStream(AutoConfigureAnnotationProcessor.PROPERTIES_PATH);
.getResourceAsStream(AutoConfigureAnnotationProcessor.PROPERTIES_PATH);
consumer.accept(propertiesFile);
});
}

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.
@@ -45,21 +45,21 @@ public class TestAutoConfigureAnnotationProcessor extends AutoConfigureAnnotatio
List<PropertyGenerator> generators = new ArrayList<>();
String annotationPackage = "org.springframework.boot.autoconfigureprocessor";
generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnClass")
.withAnnotation("TestConditionalOnClass", new OnClassConditionValueExtractor()));
.withAnnotation("TestConditionalOnClass", new OnClassConditionValueExtractor()));
generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnBean")
.withAnnotation("TestConditionalOnBean", new OnBeanConditionValueExtractor()));
.withAnnotation("TestConditionalOnBean", new OnBeanConditionValueExtractor()));
generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnSingleCandidate")
.withAnnotation("TestConditionalOnSingleCandidate", new OnBeanConditionValueExtractor()));
.withAnnotation("TestConditionalOnSingleCandidate", new OnBeanConditionValueExtractor()));
generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnWebApplication")
.withAnnotation("TestConditionalOnWebApplication", ValueExtractor.allFrom("type")));
.withAnnotation("TestConditionalOnWebApplication", ValueExtractor.allFrom("type")));
generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureBefore", true)
.withAnnotation("TestAutoConfigureBefore", ValueExtractor.allFrom("value", "name"))
.withAnnotation("TestAutoConfiguration", ValueExtractor.allFrom("before", "beforeName")));
.withAnnotation("TestAutoConfigureBefore", ValueExtractor.allFrom("value", "name"))
.withAnnotation("TestAutoConfiguration", ValueExtractor.allFrom("before", "beforeName")));
generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureAfter", true)
.withAnnotation("TestAutoConfigureAfter", ValueExtractor.allFrom("value", "name"))
.withAnnotation("TestAutoConfiguration", ValueExtractor.allFrom("after", "afterName")));
.withAnnotation("TestAutoConfigureAfter", ValueExtractor.allFrom("value", "name"))
.withAnnotation("TestAutoConfiguration", ValueExtractor.allFrom("after", "afterName")));
generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureOrder")
.withAnnotation("TestAutoConfigureOrder", ValueExtractor.allFrom("value")));
.withAnnotation("TestAutoConfigureOrder", ValueExtractor.allFrom("value")));
return generators;
}

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.
@@ -62,7 +62,7 @@ class BuilderBuildpack implements Buildpack {
static Buildpack resolve(BuildpackResolverContext context, BuildpackReference reference) {
boolean unambiguous = reference.hasPrefix(PREFIX);
BuilderReference builderReference = BuilderReference
.of(unambiguous ? reference.getSubReference(PREFIX) : reference.toString());
.of(unambiguous ? reference.getSubReference(PREFIX) : reference.toString());
BuildpackMetadata buildpackMetadata = findBuildpackMetadata(context, builderReference);
if (unambiguous) {
Assert.isTrue(buildpackMetadata != null, () -> "Buildpack '" + reference + "' not found in builder");

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.
@@ -118,8 +118,9 @@ final class BuildpackLayersMetadata extends MappedObject {
private static Buildpacks fromJson(JsonNode node) {
Buildpacks buildpacks = new Buildpacks();
node.fields().forEachRemaining((field) -> buildpacks.addBuildpackVersions(field.getKey(),
BuildpackVersions.fromJson(field.getValue())));
node.fields()
.forEachRemaining((field) -> buildpacks.addBuildpackVersions(field.getKey(),
BuildpackVersions.fromJson(field.getValue())));
return buildpacks;
}
@@ -139,8 +140,9 @@ final class BuildpackLayersMetadata extends MappedObject {
private static BuildpackVersions fromJson(JsonNode node) {
BuildpackVersions versions = new BuildpackVersions();
node.fields().forEachRemaining((field) -> versions.addBuildpackVersion(field.getKey(),
BuildpackLayerDetails.fromJson(field.getValue())));
node.fields()
.forEachRemaining((field) -> versions.addBuildpackVersion(field.getKey(),
BuildpackLayerDetails.fromJson(field.getValue())));
return versions;
}

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.
@@ -71,7 +71,7 @@ final class ImageBuildpack implements Buildpack {
private boolean buildpackExistsInBuilder(BuildpackResolverContext context, List<LayerId> imageLayers) {
BuildpackLayerDetails buildpackLayerDetails = context.getBuildpackLayersMetadata()
.getBuildpack(this.coordinates.getId(), this.coordinates.getVersion());
.getBuildpack(this.coordinates.getId(), this.coordinates.getVersion());
String layerDiffId = (buildpackLayerDetails != null) ? buildpackLayerDetails.getLayerDiffId() : null;
return (layerDiffId != null) && imageLayers.stream().map(LayerId::toString).anyMatch(layerDiffId::equals);
}
@@ -98,7 +98,7 @@ final class ImageBuildpack implements Buildpack {
boolean unambiguous = reference.hasPrefix(PREFIX);
try {
ImageReference imageReference = ImageReference
.of((unambiguous) ? reference.getSubReference(PREFIX) : reference.toString());
.of((unambiguous) ? reference.getSubReference(PREFIX) : reference.toString());
return new ImageBuildpack(context, imageReference);
}
catch (IllegalArgumentException ex) {

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.
@@ -239,8 +239,8 @@ class Lifecycle implements Closeable {
}
try {
TarArchive applicationContent = this.request.getApplicationContent(this.builder.getBuildOwner());
return this.docker.container().create(config,
ContainerContent.of(applicationContent, Directory.APPLICATION));
return this.docker.container()
.create(config, ContainerContent.of(applicationContent, Directory.APPLICATION));
}
finally {
this.applicationVolumePopulated = true;

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.
@@ -28,7 +28,8 @@ import org.springframework.util.Assert;
class LifecycleVersion implements Comparable<LifecycleVersion> {
private static final Comparator<LifecycleVersion> COMPARATOR = Comparator.comparingInt(LifecycleVersion::getMajor)
.thenComparingInt(LifecycleVersion::getMinor).thenComparing(LifecycleVersion::getPatch);
.thenComparingInt(LifecycleVersion::getMinor)
.thenComparing(LifecycleVersion::getPatch);
private final int major;

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.
@@ -339,7 +339,7 @@ public class DockerApi {
URI createUri = buildUrl("/containers/create");
try (Response response = http().post(createUri, "application/json", config::writeTo)) {
return ContainerReference
.of(SharedObjectMapper.get().readTree(response.getContent()).at("/Id").asText());
.of(SharedObjectMapper.get().readTree(response.getContent()).at("/Id").asText());
}
}

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.
@@ -56,10 +56,10 @@ import org.springframework.util.Assert;
public class ImageArchive implements TarArchive {
private static final Instant WINDOWS_EPOCH_PLUS_SECOND = OffsetDateTime.of(1980, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC)
.toInstant();
.toInstant();
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ISO_ZONED_DATE_TIME
.withZone(ZoneOffset.UTC);
.withZone(ZoneOffset.UTC);
private static final String EMPTY_LAYER_NAME_PREFIX = "blank_";

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.
@@ -66,7 +66,7 @@ final class Regex implements CharSequence {
static final Pattern TAG = Regex.of("^[\\w][\\w.-]{0,127}").compile();
static final Pattern DIGEST = Regex.of("^[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[A-Fa-f0-9]]{32,}")
.compile();
.compile();
private final String value;

View File

@@ -35,19 +35,19 @@ class ApiVersionTests {
@Test
void parseWhenVersionIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ApiVersion.parse(null))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test
void parseWhenVersionIsEmptyThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ApiVersion.parse(""))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test
void parseWhenVersionDoesNotMatchPatternThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ApiVersion.parse("bad"))
.withMessage("Malformed version number 'bad'");
.withMessage("Malformed version number 'bad'");
}
@Test
@@ -65,8 +65,8 @@ class ApiVersionTests {
@Test
void assertSupportsWhenDoesNotSupportThrowsException() {
assertThatIllegalStateException()
.isThrownBy(() -> ApiVersion.parse("1.2").assertSupports(ApiVersion.parse("1.3")))
.withMessage("Detected platform API version '1.3' does not match supported version '1.2'");
.isThrownBy(() -> ApiVersion.parse("1.2").assertSupports(ApiVersion.parse("1.3")))
.withMessage("Detected platform API version '1.3' does not match supported version '1.2'");
}
@Test
@@ -129,7 +129,7 @@ class ApiVersionTests {
private boolean supportsAny(String v1, String... others) {
return ApiVersion.parse(v1)
.supportsAny(Arrays.stream(others).map(ApiVersion::parse).toArray(ApiVersion[]::new));
.supportsAny(Arrays.stream(others).map(ApiVersion::parse).toArray(ApiVersion[]::new));
}
}

View File

@@ -63,8 +63,8 @@ class ApiVersionsTests {
@Test
void findLatestWhenNoneSupportedThrowsException() {
assertThatIllegalStateException()
.isThrownBy(() -> ApiVersions.parse("1.1", "1.2").findLatestSupported("1.3", "1.4")).withMessage(
"Detected platform API versions '1.3,1.4' are not included in supported versions '1.1,1.2'");
.isThrownBy(() -> ApiVersions.parse("1.1", "1.2").findLatestSupported("1.3", "1.4"))
.withMessage("Detected platform API versions '1.3,1.4' are not included in supported versions '1.1,1.2'");
}
@Test

View File

@@ -47,7 +47,7 @@ class BuildOwnerTests {
@Test
void fromEnvWhenEnvIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuildOwner.fromEnv(null))
.withMessage("Env must not be null");
.withMessage("Env must not be null");
}
@Test
@@ -55,7 +55,7 @@ class BuildOwnerTests {
Map<String, String> env = new LinkedHashMap<>();
env.put("CNB_GROUP_ID", "456");
assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env))
.withMessage("Missing 'CNB_USER_ID' value from the builder environment '" + env + "'");
.withMessage("Missing 'CNB_USER_ID' value from the builder environment '" + env + "'");
}
@Test
@@ -63,7 +63,7 @@ class BuildOwnerTests {
Map<String, String> env = new LinkedHashMap<>();
env.put("CNB_USER_ID", "123");
assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env))
.withMessage("Missing 'CNB_GROUP_ID' value from the builder environment '" + env + "'");
.withMessage("Missing 'CNB_GROUP_ID' value from the builder environment '" + env + "'");
}
@Test
@@ -72,7 +72,7 @@ class BuildOwnerTests {
env.put("CNB_USER_ID", "nope");
env.put("CNB_GROUP_ID", "456");
assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env))
.withMessage("Malformed 'CNB_USER_ID' value 'nope' in the builder environment '" + env + "'");
.withMessage("Malformed 'CNB_USER_ID' value 'nope' in the builder environment '" + env + "'");
}
@Test
@@ -81,7 +81,7 @@ class BuildOwnerTests {
env.put("CNB_USER_ID", "123");
env.put("CNB_GROUP_ID", "nope");
assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env))
.withMessage("Malformed 'CNB_GROUP_ID' value 'nope' in the builder environment '" + env + "'");
.withMessage("Malformed 'CNB_GROUP_ID' value 'nope' in the builder environment '" + env + "'");
}
}

View File

@@ -78,32 +78,33 @@ class BuildRequestTests {
@Test
void forJarFileWhenJarFileIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuildRequest.forJarFile(null))
.withMessage("JarFile must not be null");
.withMessage("JarFile must not be null");
}
@Test
void forJarFileWhenJarFileIsMissingThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> BuildRequest.forJarFile(new File(this.tempDir, "missing.jar")))
.withMessage("JarFile must exist");
.isThrownBy(() -> BuildRequest.forJarFile(new File(this.tempDir, "missing.jar")))
.withMessage("JarFile must exist");
}
@Test
void forJarFileWhenJarFileIsDirectoryThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuildRequest.forJarFile(this.tempDir))
.withMessage("JarFile must be a file");
.withMessage("JarFile must be a file");
}
@Test
void withBuilderUpdatesBuilder() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"))
.withBuilder(ImageReference.of("spring/builder"));
.withBuilder(ImageReference.of("spring/builder"));
assertThat(request.getBuilder()).hasToString("docker.io/spring/builder:latest");
}
@Test
void withBuilderWhenHasDigestUpdatesBuilder() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")).withBuilder(ImageReference
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"))
.withBuilder(ImageReference
.of("spring/builder@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d"));
assertThat(request.getBuilder()).hasToString(
"docker.io/spring/builder@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
@@ -112,13 +113,14 @@ class BuildRequestTests {
@Test
void withRunImageUpdatesRunImage() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"))
.withRunImage(ImageReference.of("example.com/custom/run-image:latest"));
.withRunImage(ImageReference.of("example.com/custom/run-image:latest"));
assertThat(request.getRunImage()).hasToString("example.com/custom/run-image:latest");
}
@Test
void withRunImageWhenHasDigestUpdatesRunImage() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")).withRunImage(ImageReference
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"))
.withRunImage(ImageReference
.of("example.com/custom/run-image@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d"));
assertThat(request.getRunImage()).hasToString(
"example.com/custom/run-image@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
@@ -157,14 +159,14 @@ class BuildRequestTests {
void withEnvWhenKeyIsNullThrowsException() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
assertThatIllegalArgumentException().isThrownBy(() -> request.withEnv(null, "test"))
.withMessage("Name must not be empty");
.withMessage("Name must not be empty");
}
@Test
void withEnvWhenValueIsNullThrowsException() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
assertThatIllegalArgumentException().isThrownBy(() -> request.withEnv("test", null))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test
@@ -181,7 +183,7 @@ class BuildRequestTests {
void withBuildpacksWhenBuildpacksIsNullThrowsException() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
assertThatIllegalArgumentException().isThrownBy(() -> request.withBuildpacks((List<BuildpackReference>) null))
.withMessage("Buildpacks must not be null");
.withMessage("Buildpacks must not be null");
}
@Test
@@ -198,7 +200,7 @@ class BuildRequestTests {
void withBindingsWhenBindingsIsNullThrowsException() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
assertThatIllegalArgumentException().isThrownBy(() -> request.withBindings((List<Binding>) null))
.withMessage("Bindings must not be null");
.withMessage("Bindings must not be null");
}
@Test
@@ -223,7 +225,7 @@ class BuildRequestTests {
void withTagsWhenTagsIsNullThrowsException() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
assertThatIllegalArgumentException().isThrownBy(() -> request.withTags((List<ImageReference>) null))
.withMessage("Tags must not be null");
.withMessage("Tags must not be null");
}
@Test
@@ -238,7 +240,7 @@ class BuildRequestTests {
void withBuildVolumeCacheWhenCacheIsNullThrowsException() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
assertThatIllegalArgumentException().isThrownBy(() -> request.withBuildCache(null))
.withMessage("BuildCache must not be null");
.withMessage("BuildCache must not be null");
}
@Test
@@ -253,7 +255,7 @@ class BuildRequestTests {
void withLaunchVolumeCacheWhenCacheIsNullThrowsException() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
assertThatIllegalArgumentException().isThrownBy(() -> request.withLaunchCache(null))
.withMessage("LaunchCache must not be null");
.withMessage("LaunchCache must not be null");
}
private void hasExpectedJarContent(TarArchive archive) {

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.
@@ -52,7 +52,7 @@ class BuilderBuildpackTests extends AbstractJsonTests {
BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:paketo-buildpacks/spring-boot@3.5.0");
Buildpack buildpack = BuilderBuildpack.resolve(this.resolverContext, reference);
assertThat(buildpack.getCoordinates())
.isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0"));
.isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0"));
assertThatNoLayersAreAdded(buildpack);
}
@@ -61,7 +61,7 @@ class BuilderBuildpackTests extends AbstractJsonTests {
BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:paketo-buildpacks/spring-boot");
Buildpack buildpack = BuilderBuildpack.resolve(this.resolverContext, reference);
assertThat(buildpack.getCoordinates())
.isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0"));
.isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0"));
assertThatNoLayersAreAdded(buildpack);
}
@@ -70,7 +70,7 @@ class BuilderBuildpackTests extends AbstractJsonTests {
BuildpackReference reference = BuildpackReference.of("paketo-buildpacks/spring-boot@3.5.0");
Buildpack buildpack = BuilderBuildpack.resolve(this.resolverContext, reference);
assertThat(buildpack.getCoordinates())
.isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0"));
.isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0"));
assertThatNoLayersAreAdded(buildpack);
}
@@ -79,7 +79,7 @@ class BuilderBuildpackTests extends AbstractJsonTests {
BuildpackReference reference = BuildpackReference.of("paketo-buildpacks/spring-boot");
Buildpack buildpack = BuilderBuildpack.resolve(this.resolverContext, reference);
assertThat(buildpack.getCoordinates())
.isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0"));
.isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0"));
assertThatNoLayersAreAdded(buildpack);
}
@@ -87,16 +87,16 @@ class BuilderBuildpackTests extends AbstractJsonTests {
void resolveWhenFullyQualifiedBuildpackWithVersionNotInBuilderThrowsException() {
BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:example/buildpack1@1.2.3");
assertThatIllegalArgumentException().isThrownBy(() -> BuilderBuildpack.resolve(this.resolverContext, reference))
.withMessageContaining("'urn:cnb:builder:example/buildpack1@1.2.3'")
.withMessageContaining("not found in builder");
.withMessageContaining("'urn:cnb:builder:example/buildpack1@1.2.3'")
.withMessageContaining("not found in builder");
}
@Test
void resolveWhenFullyQualifiedBuildpackWithoutVersionNotInBuilderThrowsException() {
BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:example/buildpack1");
assertThatIllegalArgumentException().isThrownBy(() -> BuilderBuildpack.resolve(this.resolverContext, reference))
.withMessageContaining("'urn:cnb:builder:example/buildpack1'")
.withMessageContaining("not found in builder");
.withMessageContaining("'urn:cnb:builder:example/buildpack1'")
.withMessageContaining("not found in builder");
}
@Test

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.
@@ -51,28 +51,28 @@ class BuilderMetadataTests extends AbstractJsonTests {
assertThat(metadata.getLifecycle().getApi().getPlatform()).isEqualTo("0.3");
assertThat(metadata.getCreatedBy().getName()).isEqualTo("Pack CLI");
assertThat(metadata.getCreatedBy().getVersion())
.isEqualTo("v0.9.0 (git sha: d42c384a39f367588f2653f2a99702db910e5ad7)");
.isEqualTo("v0.9.0 (git sha: d42c384a39f367588f2653f2a99702db910e5ad7)");
assertThat(metadata.getBuildpacks()).extracting(BuildpackMetadata::getId, BuildpackMetadata::getVersion)
.contains(tuple("paketo-buildpacks/java", "4.10.0"))
.contains(tuple("paketo-buildpacks/spring-boot", "3.5.0"))
.contains(tuple("paketo-buildpacks/executable-jar", "3.1.3"))
.contains(tuple("paketo-buildpacks/graalvm", "4.1.0"))
.contains(tuple("paketo-buildpacks/java-native-image", "4.7.0"))
.contains(tuple("paketo-buildpacks/spring-boot-native-image", "2.0.1"))
.contains(tuple("paketo-buildpacks/bellsoft-liberica", "6.2.0"));
.contains(tuple("paketo-buildpacks/java", "4.10.0"))
.contains(tuple("paketo-buildpacks/spring-boot", "3.5.0"))
.contains(tuple("paketo-buildpacks/executable-jar", "3.1.3"))
.contains(tuple("paketo-buildpacks/graalvm", "4.1.0"))
.contains(tuple("paketo-buildpacks/java-native-image", "4.7.0"))
.contains(tuple("paketo-buildpacks/spring-boot-native-image", "2.0.1"))
.contains(tuple("paketo-buildpacks/bellsoft-liberica", "6.2.0"));
}
@Test
void fromImageWhenImageIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuilderMetadata.fromImage(null))
.withMessage("Image must not be null");
.withMessage("Image must not be null");
}
@Test
void fromImageWhenImageConfigIsNullThrowsException() {
Image image = mock(Image.class);
assertThatIllegalArgumentException().isThrownBy(() -> BuilderMetadata.fromImage(image))
.withMessage("ImageConfig must not be null");
.withMessage("ImageConfig must not be null");
}
@Test
@@ -82,7 +82,7 @@ class BuilderMetadataTests extends AbstractJsonTests {
given(image.getConfig()).willReturn(imageConfig);
given(imageConfig.getLabels()).willReturn(Collections.singletonMap("alpha", "a"));
assertThatIllegalArgumentException().isThrownBy(() -> BuilderMetadata.fromImage(image))
.withMessage("No 'io.buildpacks.builder.metadata' label found in image config labels 'alpha'");
.withMessage("No 'io.buildpacks.builder.metadata' label found in image config labels 'alpha'");
}
@Test
@@ -127,7 +127,7 @@ class BuilderMetadataTests extends AbstractJsonTests {
String label = imageConfigCopy.getLabels().get("io.buildpacks.builder.metadata");
BuilderMetadata metadataCopy = BuilderMetadata.fromJson(label);
assertThat(metadataCopy.getStack().getRunImage().getImage())
.isEqualTo(metadata.getStack().getRunImage().getImage());
.isEqualTo(metadata.getStack().getRunImage().getImage());
}
}

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.
@@ -64,7 +64,7 @@ class BuilderTests {
@Test
void createWhenLogIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Builder((BuildLog) null))
.withMessage("Log must not be null");
.withMessage("Log must not be null");
}
@Test
@@ -77,7 +77,7 @@ class BuilderTests {
void buildWhenRequestIsNullThrowsException() {
Builder builder = new Builder();
assertThatIllegalArgumentException().isThrownBy(() -> builder.build(null))
.withMessage("Request must not be null");
.withMessage("Request must not be null");
}
@Test
@@ -87,19 +87,19 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest();
builder.build(request);
assertThat(out.toString()).contains("Running creator");
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
isNull());
then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
isNull());
then(docker.image()).should()
.pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull());
then(docker.image()).should()
.pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull());
then(docker.image()).should().load(archive.capture(), any());
then(docker.image()).should().remove(archive.getValue().getTag(), true);
then(docker.image()).shouldHaveNoMoreInteractions();
@@ -112,26 +112,31 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
DockerConfiguration dockerConfiguration = new DockerConfiguration()
.withBuilderRegistryTokenAuthentication("builder token")
.withPublishRegistryTokenAuthentication("publish token");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(runImage));
.withBuilderRegistryTokenAuthentication("builder token")
.withPublishRegistryTokenAuthentication("publish token");
given(docker.image()
.pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(builderImage));
given(docker.image()
.pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration);
BuildRequest request = getTestRequest().withPublish(true);
builder.build(request);
assertThat(out.toString()).contains("Running creator");
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
then(docker.image()).should().push(eq(request.getName()), any(),
eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
then(docker.image()).should()
.pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
then(docker.image()).should()
.pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
then(docker.image()).should()
.push(eq(request.getName()), any(),
eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
then(docker.image()).should().load(archive.capture(), any());
then(docker.image()).should().remove(archive.getValue().getTag(), true);
then(docker.image()).shouldHaveNoMoreInteractions();
@@ -144,9 +149,9 @@ class BuilderTests {
Image builderImage = loadImage("image-with-no-run-image-tag.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of("gcr.io/paketo-buildpacks/builder:latest")), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:latest")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest().withBuilder(ImageReference.of("gcr.io/paketo-buildpacks/builder"));
builder.build(request);
@@ -164,10 +169,12 @@ class BuilderTests {
Image builderImage = loadImage("image-with-run-image-digest.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of(
"docker.io/cloudfoundry/run@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d")),
any(), isNull())).willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image()
.pull(eq(ImageReference
.of("docker.io/cloudfoundry/run@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d")),
any(), isNull()))
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest();
builder.build(request);
@@ -185,9 +192,9 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("example.com/custom/run:latest")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest().withRunImage(ImageReference.of("example.com/custom/run:latest"));
builder.build(request);
@@ -205,13 +212,13 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
given(docker.image().inspect(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME))))
.willReturn(builderImage);
.willReturn(builderImage);
given(docker.image().inspect(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb"))))
.willReturn(runImage);
.willReturn(runImage);
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest().withPullPolicy(PullPolicy.NEVER);
builder.build(request);
@@ -231,13 +238,13 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
given(docker.image().inspect(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME))))
.willReturn(builderImage);
.willReturn(builderImage);
given(docker.image().inspect(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb"))))
.willReturn(runImage);
.willReturn(runImage);
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest().withPullPolicy(PullPolicy.ALWAYS);
builder.build(request);
@@ -257,15 +264,17 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
given(docker.image().inspect(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)))).willThrow(
new DockerEngineException("docker://localhost/", new URI("example"), 404, "NOT FOUND", null, null))
.willReturn(builderImage);
given(docker.image().inspect(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")))).willThrow(
new DockerEngineException("docker://localhost/", new URI("example"), 404, "NOT FOUND", null, null))
.willReturn(runImage);
.willAnswer(withPulledImage(runImage));
given(docker.image().inspect(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME))))
.willThrow(
new DockerEngineException("docker://localhost/", new URI("example"), 404, "NOT FOUND", null, null))
.willReturn(builderImage);
given(docker.image().inspect(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb"))))
.willThrow(
new DockerEngineException("docker://localhost/", new URI("example"), 404, "NOT FOUND", null, null))
.willReturn(runImage);
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest().withPullPolicy(PullPolicy.IF_NOT_PRESENT);
builder.build(request);
@@ -285,9 +294,9 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest().withTags(ImageReference.of("my-application:1.2.3"));
builder.build(request);
@@ -307,14 +316,16 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
DockerConfiguration dockerConfiguration = new DockerConfiguration()
.withBuilderRegistryTokenAuthentication("builder token")
.withPublishRegistryTokenAuthentication("publish token");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(runImage));
.withBuilderRegistryTokenAuthentication("builder token")
.withPublishRegistryTokenAuthentication("publish token");
given(docker.image()
.pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(builderImage));
given(docker.image()
.pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration);
BuildRequest request = getTestRequest().withPublish(true).withTags(ImageReference.of("my-application:1.2.3"));
builder.build(request);
@@ -322,15 +333,19 @@ class BuilderTests {
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
assertThat(out.toString()).contains("Successfully created image tag 'docker.io/library/my-application:1.2.3'");
then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
then(docker.image()).should().push(eq(request.getName()), any(),
eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
then(docker.image()).should()
.pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
then(docker.image()).should()
.pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
then(docker.image()).should()
.push(eq(request.getName()), any(),
eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
then(docker.image()).should().tag(eq(request.getName()), eq(ImageReference.of("my-application:1.2.3")));
then(docker.image()).should().push(eq(ImageReference.of("my-application:1.2.3")), any(),
eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
then(docker.image()).should()
.push(eq(ImageReference.of("my-application:1.2.3")), any(),
eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
then(docker.image()).should().load(archive.capture(), any());
then(docker.image()).should().remove(archive.getValue().getTag(), true);
@@ -344,13 +359,14 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image-with-bad-stack.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest();
assertThatIllegalStateException().isThrownBy(() -> builder.build(request)).withMessage(
"Run image stack 'org.cloudfoundry.stacks.cfwindowsfs3' does not match builder stack 'io.buildpacks.stacks.bionic'");
assertThatIllegalStateException().isThrownBy(() -> builder.build(request))
.withMessage(
"Run image stack 'org.cloudfoundry.stacks.cfwindowsfs3' does not match builder stack 'io.buildpacks.stacks.bionic'");
}
@Test
@@ -360,13 +376,13 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildRequest request = getTestRequest();
assertThatExceptionOfType(BuilderException.class).isThrownBy(() -> builder.build(request))
.withMessage("Builder lifecycle 'creator' failed with status code 9");
.withMessage("Builder lifecycle 'creator' failed with status code 9");
}
@Test
@@ -375,14 +391,16 @@ class BuilderTests {
DockerApi docker = mockDockerApi();
Image builderImage = loadImage("image-with-run-image-different-registry.json");
DockerConfiguration dockerConfiguration = new DockerConfiguration()
.withBuilderRegistryTokenAuthentication("builder token");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(builderImage));
.withBuilderRegistryTokenAuthentication("builder token");
given(docker.image()
.pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(builderImage));
Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration);
BuildRequest request = getTestRequest();
assertThatIllegalStateException().isThrownBy(() -> builder.build(request)).withMessage(
"Run image 'example.com/custom/run:latest' must be pulled from the 'docker.io' authenticated registry");
assertThatIllegalStateException().isThrownBy(() -> builder.build(request))
.withMessage(
"Run image 'example.com/custom/run:latest' must be pulled from the 'docker.io' authenticated registry");
}
@Test
@@ -391,14 +409,16 @@ class BuilderTests {
DockerApi docker = mockDockerApi();
Image builderImage = loadImage("image.json");
DockerConfiguration dockerConfiguration = new DockerConfiguration()
.withBuilderRegistryTokenAuthentication("builder token");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(builderImage));
.withBuilderRegistryTokenAuthentication("builder token");
given(docker.image()
.pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())))
.willAnswer(withPulledImage(builderImage));
Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration);
BuildRequest request = getTestRequest().withRunImage(ImageReference.of("example.com/custom/run:latest"));
assertThatIllegalStateException().isThrownBy(() -> builder.build(request)).withMessage(
"Run image 'example.com/custom/run:latest' must be pulled from the 'docker.io' authenticated registry");
assertThatIllegalStateException().isThrownBy(() -> builder.build(request))
.withMessage(
"Run image 'example.com/custom/run:latest' must be pulled from the 'docker.io' authenticated registry");
}
@Test
@@ -408,15 +428,15 @@ class BuilderTests {
Image builderImage = loadImage("image.json");
Image runImage = loadImage("run-image.json");
given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()))
.willAnswer(withPulledImage(builderImage));
.willAnswer(withPulledImage(builderImage));
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()))
.willAnswer(withPulledImage(runImage));
.willAnswer(withPulledImage(runImage));
Builder builder = new Builder(BuildLog.to(out), docker, null);
BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:example/buildpack@1.2.3");
BuildRequest request = getTestRequest().withBuildpacks(reference);
assertThatIllegalArgumentException().isThrownBy(() -> builder.build(request))
.withMessageContaining("'urn:cnb:builder:example/buildpack@1.2.3'")
.withMessageContaining("not found in builder");
.withMessageContaining("'urn:cnb:builder:example/buildpack@1.2.3'")
.withMessageContaining("not found in builder");
}
private DockerApi mockDockerApi() throws IOException {

View File

@@ -43,7 +43,7 @@ class BuildpackCoordinatesTests extends AbstractJsonTests {
@Test
void fromToml() throws IOException {
BuildpackCoordinates coordinates = BuildpackCoordinates
.fromToml(createTomlStream("example/buildpack1", "0.0.1", true, false), this.archive);
.fromToml(createTomlStream("example/buildpack1", "0.0.1", true, false), this.archive);
assertThat(coordinates.getId()).isEqualTo("example/buildpack1");
assertThat(coordinates.getVersion()).isEqualTo("0.0.1");
}
@@ -52,17 +52,17 @@ class BuildpackCoordinatesTests extends AbstractJsonTests {
void fromTomlWhenMissingDescriptorThrowsException() {
ByteArrayInputStream coordinates = new ByteArrayInputStream("".getBytes());
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor 'buildpack.toml' is required")
.withMessageContaining(this.archive.toString());
.withMessageContaining("Buildpack descriptor 'buildpack.toml' is required")
.withMessageContaining(this.archive.toString());
}
@Test
void fromTomlWhenMissingIDThrowsException() throws IOException {
try (InputStream coordinates = createTomlStream(null, null, true, false)) {
assertThatIllegalArgumentException()
.isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor must contain ID")
.withMessageContaining(this.archive.toString());
.isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor must contain ID")
.withMessageContaining(this.archive.toString());
}
}
@@ -70,9 +70,9 @@ class BuildpackCoordinatesTests extends AbstractJsonTests {
void fromTomlWhenMissingVersionThrowsException() throws IOException {
try (InputStream coordinates = createTomlStream("example/buildpack1", null, true, false)) {
assertThatIllegalArgumentException()
.isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor must contain version")
.withMessageContaining(this.archive.toString());
.isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor must contain version")
.withMessageContaining(this.archive.toString());
}
}
@@ -80,9 +80,9 @@ class BuildpackCoordinatesTests extends AbstractJsonTests {
void fromTomlWhenMissingStacksAndOrderThrowsException() throws IOException {
try (InputStream coordinates = createTomlStream("example/buildpack1", "0.0.1", false, false)) {
assertThatIllegalArgumentException()
.isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor must contain either 'stacks' or 'order'")
.withMessageContaining(this.archive.toString());
.isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor must contain either 'stacks' or 'order'")
.withMessageContaining(this.archive.toString());
}
}
@@ -90,16 +90,16 @@ class BuildpackCoordinatesTests extends AbstractJsonTests {
void fromTomlWhenContainsBothStacksAndOrderThrowsException() throws IOException {
try (InputStream coordinates = createTomlStream("example/buildpack1", "0.0.1", true, true)) {
assertThatIllegalArgumentException()
.isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor must not contain both 'stacks' and 'order'")
.withMessageContaining(this.archive.toString());
.isThrownBy(() -> BuildpackCoordinates.fromToml(coordinates, this.archive))
.withMessageContaining("Buildpack descriptor must not contain both 'stacks' and 'order'")
.withMessageContaining(this.archive.toString());
}
}
@Test
void fromBuildpackMetadataWhenMetadataIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackCoordinates.fromBuildpackMetadata(null))
.withMessage("BuildpackMetadata must not be null");
.withMessage("BuildpackMetadata must not be null");
}
@Test
@@ -113,7 +113,7 @@ class BuildpackCoordinatesTests extends AbstractJsonTests {
@Test
void ofWhenIdIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackCoordinates.of(null, null))
.withMessage("ID must not be empty");
.withMessage("ID must not be empty");
}
@Test

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.
@@ -42,11 +42,11 @@ class BuildpackLayersMetadataTests extends AbstractJsonTests {
Image image = Image.of(getContent("buildpack-image.json"));
BuildpackLayersMetadata metadata = BuildpackLayersMetadata.fromImage(image);
assertThat(metadata.getBuildpack("example/hello-moon", "0.0.3")).extracting("homepage", "layerDiffId")
.containsExactly("https://github.com/example/tree/main/buildpacks/hello-moon",
"sha256:4bfdc8714aee68da6662c43bc28d3b41202c88e915641c356523dabe729814c2");
.containsExactly("https://github.com/example/tree/main/buildpacks/hello-moon",
"sha256:4bfdc8714aee68da6662c43bc28d3b41202c88e915641c356523dabe729814c2");
assertThat(metadata.getBuildpack("example/hello-world", "0.0.2")).extracting("homepage", "layerDiffId")
.containsExactly("https://github.com/example/tree/main/buildpacks/hello-world",
"sha256:f752fe099c846e501bdc991d1a22f98c055ddc62f01cfc0495fff2c69f8eb940");
.containsExactly("https://github.com/example/tree/main/buildpacks/hello-world",
"sha256:f752fe099c846e501bdc991d1a22f98c055ddc62f01cfc0495fff2c69f8eb940");
assertThat(metadata.getBuildpack("example/hello-world", "version-does-not-exist")).isNull();
assertThat(metadata.getBuildpack("id-does-not-exist", "9.9.9")).isNull();
}
@@ -54,14 +54,14 @@ class BuildpackLayersMetadataTests extends AbstractJsonTests {
@Test
void fromImageWhenImageIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackLayersMetadata.fromImage(null))
.withMessage("Image must not be null");
.withMessage("Image must not be null");
}
@Test
void fromImageWhenImageConfigIsNullThrowsException() {
Image image = mock(Image.class);
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackLayersMetadata.fromImage(image))
.withMessage("ImageConfig must not be null");
.withMessage("ImageConfig must not be null");
}
@Test
@@ -71,25 +71,25 @@ class BuildpackLayersMetadataTests extends AbstractJsonTests {
given(image.getConfig()).willReturn(imageConfig);
given(imageConfig.getLabels()).willReturn(Collections.singletonMap("alpha", "a"));
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackLayersMetadata.fromImage(image))
.withMessage("No 'io.buildpacks.buildpack.layers' label found in image config labels 'alpha'");
.withMessage("No 'io.buildpacks.buildpack.layers' label found in image config labels 'alpha'");
}
@Test
void fromJsonLoadsMetadata() throws IOException {
BuildpackLayersMetadata metadata = BuildpackLayersMetadata
.fromJson(getContentAsString("buildpack-layers-metadata.json"));
.fromJson(getContentAsString("buildpack-layers-metadata.json"));
assertThat(metadata.getBuildpack("example/hello-moon", "0.0.3")).extracting("name", "homepage", "layerDiffId")
.containsExactly("Example hello-moon buildpack",
"https://github.com/example/tree/main/buildpacks/hello-moon",
"sha256:4bfdc8714aee68da6662c43bc28d3b41202c88e915641c356523dabe729814c2");
.containsExactly("Example hello-moon buildpack",
"https://github.com/example/tree/main/buildpacks/hello-moon",
"sha256:4bfdc8714aee68da6662c43bc28d3b41202c88e915641c356523dabe729814c2");
assertThat(metadata.getBuildpack("example/hello-world", "0.0.1")).extracting("name", "homepage", "layerDiffId")
.containsExactly("Example hello-world buildpack",
"https://github.com/example/tree/main/buildpacks/hello-world",
"sha256:1c90e0b80d92555a0523c9ee6500845328fc39ba9dca9d30a877ff759ffbff28");
.containsExactly("Example hello-world buildpack",
"https://github.com/example/tree/main/buildpacks/hello-world",
"sha256:1c90e0b80d92555a0523c9ee6500845328fc39ba9dca9d30a877ff759ffbff28");
assertThat(metadata.getBuildpack("example/hello-world", "0.0.2")).extracting("name", "homepage", "layerDiffId")
.containsExactly("Example hello-world buildpack",
"https://github.com/example/tree/main/buildpacks/hello-world",
"sha256:f752fe099c846e501bdc991d1a22f98c055ddc62f01cfc0495fff2c69f8eb940");
.containsExactly("Example hello-world buildpack",
"https://github.com/example/tree/main/buildpacks/hello-world",
"sha256:f752fe099c846e501bdc991d1a22f98c055ddc62f01cfc0495fff2c69f8eb940");
assertThat(metadata.getBuildpack("example/hello-world", "version-does-not-exist")).isNull();
assertThat(metadata.getBuildpack("id-does-not-exist", "9.9.9")).isNull();
}

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.
@@ -48,14 +48,14 @@ class BuildpackMetadataTests extends AbstractJsonTests {
@Test
void fromImageWhenImageIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackMetadata.fromImage(null))
.withMessage("Image must not be null");
.withMessage("Image must not be null");
}
@Test
void fromImageWhenImageConfigIsNullThrowsException() {
Image image = mock(Image.class);
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackMetadata.fromImage(image))
.withMessage("ImageConfig must not be null");
.withMessage("ImageConfig must not be null");
}
@Test
@@ -65,7 +65,7 @@ class BuildpackMetadataTests extends AbstractJsonTests {
given(image.getConfig()).willReturn(imageConfig);
given(imageConfig.getLabels()).willReturn(Collections.singletonMap("alpha", "a"));
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackMetadata.fromImage(image))
.withMessage("No 'io.buildpacks.buildpackage.metadata' label found in image config labels 'alpha'");
.withMessage("No 'io.buildpacks.buildpackage.metadata' label found in image config labels 'alpha'");
}
@Test

View File

@@ -33,7 +33,7 @@ class BuildpackReferenceTests {
@Test
void ofWhenValueIsEmptyThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> BuildpackReference.of(""))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test

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.
@@ -96,9 +96,9 @@ class BuildpackResolversTests extends AbstractJsonTests {
void resolveAllWithInvalidLocatorThrowsException() {
BuildpackReference reference = BuildpackReference.of("unknown-buildpack@0.0.1");
assertThatIllegalArgumentException()
.isThrownBy(() -> BuildpackResolvers.resolveAll(this.resolverContext, Collections.singleton(reference)))
.withMessageContaining("Invalid buildpack reference")
.withMessageContaining("'unknown-buildpack@0.0.1'");
.isThrownBy(() -> BuildpackResolvers.resolveAll(this.resolverContext, Collections.singleton(reference)))
.withMessageContaining("Invalid buildpack reference")
.withMessageContaining("'unknown-buildpack@0.0.1'");
}
}

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.
@@ -90,9 +90,9 @@ class DirectoryBuildpackTests {
Files.createDirectories(this.buildpackDir.toPath());
BuildpackReference reference = BuildpackReference.of(this.buildpackDir.toString());
assertThatIllegalArgumentException()
.isThrownBy(() -> DirectoryBuildpack.resolve(this.resolverContext, reference))
.withMessageContaining("Buildpack descriptor 'buildpack.toml' is required")
.withMessageContaining(this.buildpackDir.getAbsolutePath());
.isThrownBy(() -> DirectoryBuildpack.resolve(this.resolverContext, reference))
.withMessageContaining("Buildpack descriptor 'buildpack.toml' is required")
.withMessageContaining(this.buildpackDir.getAbsolutePath());
}
@Test
@@ -133,13 +133,14 @@ class DirectoryBuildpackTests {
entries.add(entry);
entry = tar.getNextTarEntry();
}
assertThat(entries).extracting("name", "mode").containsExactlyInAnyOrder(tuple("/cnb/", 0755),
tuple("/cnb/buildpacks/", 0755), tuple("/cnb/buildpacks/example_buildpack1/", 0755),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/", 0755),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/buildpack.toml", 0644),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/bin/", 0755),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/bin/detect", 0744),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/bin/build", 0744));
assertThat(entries).extracting("name", "mode")
.containsExactlyInAnyOrder(tuple("/cnb/", 0755), tuple("/cnb/buildpacks/", 0755),
tuple("/cnb/buildpacks/example_buildpack1/", 0755),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/", 0755),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/buildpack.toml", 0644),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/bin/", 0755),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/bin/detect", 0744),
tuple("/cnb/buildpacks/example_buildpack1/0.0.1/bin/build", 0744));
}
}

View File

@@ -144,7 +144,7 @@ class EphemeralBuilderTests extends AbstractJsonTests {
this.creator, this.env, this.buildpacks);
ImageConfig config = builder.getArchive().getImageConfig();
assertThat(config.getLabels())
.contains(entry(EphemeralBuilder.BUILDER_FOR_LABEL_NAME, this.targetImage.toString()));
.contains(entry(EphemeralBuilder.BUILDER_FOR_LABEL_NAME, this.targetImage.toString()));
}
@Test
@@ -164,7 +164,7 @@ class EphemeralBuilderTests extends AbstractJsonTests {
"/cnb/buildpacks/example_buildpack3/0.0.3/buildpack.toml");
File orderDirectory = unpack(getLayer(builder.getArchive(), EXISTING_IMAGE_LAYER_COUNT + 3), "order");
assertThat(new File(orderDirectory, "cnb/order.toml")).usingCharset(StandardCharsets.UTF_8)
.hasContent(content("order.toml"));
.hasContent(content("order.toml"));
}
private void assertBuildpackLayerContent(EphemeralBuilder builder, int index, String s) throws Exception {

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.
@@ -126,7 +126,7 @@ class ImageBuildpackTests extends AbstractJsonTests {
ImageReference imageReference = ImageReference.of("example/buildpack1:1.0.0");
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
given(resolverContext.getBuildpackLayersMetadata())
.willReturn(BuildpackLayersMetadata.fromJson(getContentAsString("buildpack-layers-metadata.json")));
.willReturn(BuildpackLayersMetadata.fromJson(getContentAsString("buildpack-layers-metadata.json")));
given(resolverContext.fetchImage(eq(imageReference), eq(ImageType.BUILDPACK))).willReturn(image);
willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any());
BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:1.0.0");
@@ -141,8 +141,8 @@ class ImageBuildpackTests extends AbstractJsonTests {
given(resolverContext.fetchImage(any(), any())).willThrow(IOException.class);
BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1");
assertThatIllegalArgumentException().isThrownBy(() -> ImageBuildpack.resolve(resolverContext, reference))
.withMessageContaining("Error pulling buildpack image")
.withMessageContaining("example/buildpack1:latest");
.withMessageContaining("Error pulling buildpack image")
.withMessageContaining("example/buildpack1:latest");
}
@Test
@@ -152,7 +152,7 @@ class ImageBuildpackTests extends AbstractJsonTests {
given(resolverContext.fetchImage(any(), any())).willReturn(image);
BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:latest");
assertThatIllegalArgumentException().isThrownBy(() -> ImageBuildpack.resolve(resolverContext, reference))
.withMessageContaining("No 'io.buildpacks.buildpackage.metadata' label found");
.withMessageContaining("No 'io.buildpacks.buildpackage.metadata' label found");
}
@Test
@@ -160,7 +160,7 @@ class ImageBuildpackTests extends AbstractJsonTests {
BuildpackReference reference = BuildpackReference.of("docker://buildpack@0.0.1");
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
assertThatIllegalArgumentException().isThrownBy(() -> ImageBuildpack.resolve(resolverContext, reference))
.withMessageContaining("Unable to parse image reference \"buildpack@0.0.1\"");
.withMessageContaining("Unable to parse image reference \"buildpack@0.0.1\"");
}
@Test
@@ -217,14 +217,14 @@ class ImageBuildpackTests extends AbstractJsonTests {
entry = tar.getNextTarEntry();
}
}
assertThat(entries).extracting("name", "mode").containsExactlyInAnyOrder(
tuple("cnb/", TarArchiveEntry.DEFAULT_DIR_MODE),
tuple("cnb/buildpacks/", TarArchiveEntry.DEFAULT_DIR_MODE),
tuple("cnb/buildpacks/example_buildpack/", TarArchiveEntry.DEFAULT_DIR_MODE),
tuple("cnb/buildpacks/example_buildpack/0.0.1/", TarArchiveEntry.DEFAULT_DIR_MODE),
tuple("cnb/buildpacks/example_buildpack/0.0.1/buildpack.toml", TarArchiveEntry.DEFAULT_FILE_MODE),
tuple("cnb/buildpacks/example_buildpack/0.0.1/" + this.longFilePath,
TarArchiveEntry.DEFAULT_FILE_MODE));
assertThat(entries).extracting("name", "mode")
.containsExactlyInAnyOrder(tuple("cnb/", TarArchiveEntry.DEFAULT_DIR_MODE),
tuple("cnb/buildpacks/", TarArchiveEntry.DEFAULT_DIR_MODE),
tuple("cnb/buildpacks/example_buildpack/", TarArchiveEntry.DEFAULT_DIR_MODE),
tuple("cnb/buildpacks/example_buildpack/0.0.1/", TarArchiveEntry.DEFAULT_DIR_MODE),
tuple("cnb/buildpacks/example_buildpack/0.0.1/buildpack.toml", TarArchiveEntry.DEFAULT_FILE_MODE),
tuple("cnb/buildpacks/example_buildpack/0.0.1/" + this.longFilePath,
TarArchiveEntry.DEFAULT_FILE_MODE));
}
private void assertAppliesNoLayers(Buildpack buildpack) throws IOException {

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.
@@ -135,7 +135,7 @@ class LifecycleTests {
Lifecycle lifecycle = createLifecycle();
lifecycle.execute();
assertThatIllegalStateException().isThrownBy(lifecycle::execute)
.withMessage("Lifecycle has already been executed");
.withMessage("Lifecycle has already been executed");
}
@Test
@@ -144,7 +144,7 @@ class LifecycleTests {
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(9, null));
assertThatExceptionOfType(BuilderException.class).isThrownBy(() -> createLifecycle().execute())
.withMessage("Builder lifecycle 'creator' failed with status code 9");
.withMessage("Builder lifecycle 'creator' failed with status code 9");
}
@Test
@@ -165,8 +165,8 @@ class LifecycleTests {
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
assertThatIllegalStateException()
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-api.json").execute())
.withMessageContaining("Detected platform API versions '0.2' are not included in supported versions");
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-api.json").execute())
.withMessageContaining("Detected platform API versions '0.2' are not included in supported versions");
}
@Test
@@ -175,9 +175,8 @@ class LifecycleTests {
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
assertThatIllegalStateException()
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-apis.json").execute())
.withMessageContaining(
"Detected platform API versions '0.1,0.2' are not included in supported versions");
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-apis.json").execute())
.withMessageContaining("Detected platform API versions '0.1,0.2' are not included in supported versions");
}
@Test
@@ -213,7 +212,7 @@ class LifecycleTests {
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
BuildRequest request = getTestRequest().withBuildCache(Cache.volume("build-volume"))
.withLaunchCache(Cache.volume("launch-volume"));
.withLaunchCache(Cache.volume("launch-volume"));
createLifecycle(request).execute();
assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-cache-volumes.json"));
assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");

View File

@@ -31,19 +31,19 @@ class LifecycleVersionTests {
@Test
void parseWhenValueIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> LifecycleVersion.parse(null))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test
void parseWhenTooLongThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> LifecycleVersion.parse("v1.2.3.4"))
.withMessage("Malformed version number '1.2.3.4'");
.withMessage("Malformed version number '1.2.3.4'");
}
@Test
void parseWhenNonNumericThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> LifecycleVersion.parse("v1.2.3a"))
.withMessage("Malformed version number '1.2.3a'");
.withMessage("Malformed version number '1.2.3a'");
}
@Test

View File

@@ -39,7 +39,7 @@ class StackIdTests {
@Test
void fromImageWhenImageIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> StackId.fromImage(null))
.withMessage("Image must not be null");
.withMessage("Image must not be null");
}
@Test
@@ -48,7 +48,7 @@ class StackIdTests {
ImageConfig imageConfig = mock(ImageConfig.class);
given(image.getConfig()).willReturn(imageConfig);
assertThatIllegalStateException().isThrownBy(() -> StackId.fromImage(image))
.withMessage("Missing 'io.buildpacks.stack.id' stack label");
.withMessage("Missing 'io.buildpacks.stack.id' stack label");
}
@Test

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.
@@ -73,8 +73,8 @@ class TarGzipBuildpackTests {
Path compressedArchive = this.testTarGzip.createEmptyArchive();
BuildpackReference reference = BuildpackReference.of(compressedArchive.toString());
assertThatIllegalArgumentException().isThrownBy(() -> TarGzipBuildpack.resolve(this.resolverContext, reference))
.withMessageContaining("Buildpack descriptor 'buildpack.toml' is required")
.withMessageContaining(compressedArchive.toString());
.withMessageContaining("Buildpack descriptor 'buildpack.toml' is required")
.withMessageContaining(compressedArchive.toString());
}
@Test

View File

@@ -129,7 +129,7 @@ class TestTarGzip {
assertThat(tar.getNextEntry().getName()).isEqualTo("cnb/buildpacks/example_buildpack1/");
assertThat(tar.getNextEntry().getName()).isEqualTo("cnb/buildpacks/example_buildpack1/0.0.1/");
assertThat(tar.getNextEntry().getName())
.isEqualTo("cnb/buildpacks/example_buildpack1/0.0.1/buildpack.toml");
.isEqualTo("cnb/buildpacks/example_buildpack1/0.0.1/buildpack.toml");
assertThat(tar.getNextEntry().getName()).isEqualTo("cnb/buildpacks/example_buildpack1/0.0.1/bin/");
assertThat(tar.getNextEntry().getName()).isEqualTo("cnb/buildpacks/example_buildpack1/0.0.1/bin/detect");
assertThat(tar.getNextEntry().getName()).isEqualTo("cnb/buildpacks/example_buildpack1/0.0.1/bin/build");

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.
@@ -35,8 +35,9 @@ class DockerApiIntegrationTests {
@Test
void pullImage() throws IOException {
this.docker.image().pull(ImageReference.of("gcr.io/paketo-buildpacks/builder:base"),
new TotalProgressPullListener(new TotalProgressBar("Pulling: ")));
this.docker.image()
.pull(ImageReference.of("gcr.io/paketo-buildpacks/builder:base"),
new TotalProgressPullListener(new TotalProgressBar("Pulling: ")));
}
}

View File

@@ -151,13 +151,13 @@ class DockerApiTests {
@Test
void pullWhenReferenceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.pull(null, this.pullListener))
.withMessage("Reference must not be null");
.withMessage("Reference must not be null");
}
@Test
void pullWhenListenerIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.pull(ImageReference.of("ubuntu"), null))
.withMessage("Listener must not be null");
.withMessage("Listener must not be null");
}
@Test
@@ -193,14 +193,14 @@ class DockerApiTests {
@Test
void pushWhenReferenceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.push(null, this.pushListener, null))
.withMessage("Reference must not be null");
.withMessage("Reference must not be null");
}
@Test
void pushWhenListenerIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.api.push(ImageReference.of("ubuntu"), null, null))
.withMessage("Listener must not be null");
.isThrownBy(() -> this.api.push(ImageReference.of("ubuntu"), null, null))
.withMessage("Listener must not be null");
}
@Test
@@ -221,21 +221,21 @@ class DockerApiTests {
URI pushUri = new URI(IMAGES_URL + "/localhost:5000/ubuntu/push");
given(http().post(pushUri, "auth token")).willReturn(responseOf("push-stream-with-error.json"));
assertThatIllegalStateException()
.isThrownBy(() -> this.api.push(reference, this.pushListener, "auth token"))
.withMessageContaining("test message");
.isThrownBy(() -> this.api.push(reference, this.pushListener, "auth token"))
.withMessageContaining("test message");
}
@Test
void loadWhenArchiveIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.load(null, UpdateListener.none()))
.withMessage("Archive must not be null");
.withMessage("Archive must not be null");
}
@Test
void loadWhenListenerIsNullThrowsException() {
ImageArchive archive = mock(ImageArchive.class);
assertThatIllegalArgumentException().isThrownBy(() -> this.api.load(archive, null))
.withMessage("Listener must not be null");
.withMessage("Listener must not be null");
}
@Test // gh-23130
@@ -245,7 +245,7 @@ class DockerApiTests {
URI loadUri = new URI(IMAGES_URL + "/load");
given(http().post(eq(loadUri), eq("application/x-tar"), any())).willReturn(emptyResponse());
assertThatIllegalStateException().isThrownBy(() -> this.api.load(archive, this.loadListener))
.withMessageContaining("Invalid response received");
.withMessageContaining("Invalid response received");
}
@Test
@@ -268,13 +268,13 @@ class DockerApiTests {
@Test
void removeWhenReferenceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.remove(null, true))
.withMessage("Reference must not be null");
.withMessage("Reference must not be null");
}
@Test
void removeRemovesContainer() throws Exception {
ImageReference reference = ImageReference
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
URI removeUri = new URI(IMAGES_URL
+ "/docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
given(http().delete(removeUri)).willReturn(emptyResponse());
@@ -285,7 +285,7 @@ class DockerApiTests {
@Test
void removeWhenForceIsTrueRemovesContainer() throws Exception {
ImageReference reference = ImageReference
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
URI removeUri = new URI(IMAGES_URL
+ "/docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d?force=1");
given(http().delete(removeUri)).willReturn(emptyResponse());
@@ -296,7 +296,7 @@ class DockerApiTests {
@Test
void inspectWhenReferenceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.inspect(null))
.withMessage("Reference must not be null");
.withMessage("Reference must not be null");
}
@Test
@@ -318,7 +318,7 @@ class DockerApiTests {
void exportLayersWhenExportsIsNullThrowsException() {
ImageReference reference = ImageReference.of("gcr.io/paketo-buildpacks/builder:base");
assertThatIllegalArgumentException().isThrownBy(() -> this.api.exportLayers(reference, null))
.withMessage("Exports must not be null");
.withMessage("Exports must not be null");
}
@Test
@@ -339,26 +339,26 @@ class DockerApiTests {
}
}
});
assertThat(contents).hasSize(3).containsKeys(
"1bf6c63a1e9ed1dd7cb961273bf60b8e0f440361faf273baf866f408e4910601/layer.tar",
"8fdfb915302159a842cbfae6faec5311b00c071ebf14e12da7116ae7532e9319/layer.tar",
"93cd584bb189bfca4f51744bd19d836fd36da70710395af5a1523ee88f208c6a/layer.tar");
assertThat(contents).hasSize(3)
.containsKeys("1bf6c63a1e9ed1dd7cb961273bf60b8e0f440361faf273baf866f408e4910601/layer.tar",
"8fdfb915302159a842cbfae6faec5311b00c071ebf14e12da7116ae7532e9319/layer.tar",
"93cd584bb189bfca4f51744bd19d836fd36da70710395af5a1523ee88f208c6a/layer.tar");
assertThat(contents.get("1bf6c63a1e9ed1dd7cb961273bf60b8e0f440361faf273baf866f408e4910601/layer.tar"))
.containsExactly("etc/", "etc/apt/", "etc/apt/sources.list");
.containsExactly("etc/", "etc/apt/", "etc/apt/sources.list");
}
@Test
void tagWhenReferenceIsNullThrowsException() {
ImageReference tag = ImageReference.of("localhost:5000/ubuntu");
assertThatIllegalArgumentException().isThrownBy(() -> this.api.tag(null, tag))
.withMessage("SourceReference must not be null");
.withMessage("SourceReference must not be null");
}
@Test
void tagWhenTargetIsNullThrowsException() {
ImageReference reference = ImageReference.of("localhost:5000/ubuntu");
assertThatIllegalArgumentException().isThrownBy(() -> this.api.tag(reference, null))
.withMessage("TargetReference must not be null");
.withMessage("TargetReference must not be null");
}
@Test
@@ -392,7 +392,7 @@ class DockerApiTests {
@Test
void createWhenConfigIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.create(null))
.withMessage("Config must not be null");
.withMessage("Config must not be null");
}
@Test
@@ -401,7 +401,7 @@ class DockerApiTests {
ContainerConfig config = ContainerConfig.of(imageReference, (update) -> update.withCommand("/bin/bash"));
URI createUri = new URI(CONTAINERS_URL + "/create");
given(http().post(eq(createUri), eq("application/json"), any()))
.willReturn(responseOf("create-container-response.json"));
.willReturn(responseOf("create-container-response.json"));
ContainerReference containerReference = this.api.create(config);
assertThat(containerReference).hasToString("e90e34656806");
then(http()).should().post(any(), any(), this.writer.capture());
@@ -421,7 +421,7 @@ class DockerApiTests {
ContainerContent content = ContainerContent.of(archive);
URI createUri = new URI(CONTAINERS_URL + "/create");
given(http().post(eq(createUri), eq("application/json"), any()))
.willReturn(responseOf("create-container-response.json"));
.willReturn(responseOf("create-container-response.json"));
URI uploadUri = new URI(CONTAINERS_URL + "/e90e34656806/archive?path=%2F");
given(http().put(eq(uploadUri), eq("application/x-tar"), any())).willReturn(emptyResponse());
ContainerReference containerReference = this.api.create(config, content);
@@ -438,7 +438,7 @@ class DockerApiTests {
@Test
void startWhenReferenceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.start(null))
.withMessage("Reference must not be null");
.withMessage("Reference must not be null");
}
@Test
@@ -453,14 +453,14 @@ class DockerApiTests {
@Test
void logsWhenReferenceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.logs(null, UpdateListener.none()))
.withMessage("Reference must not be null");
.withMessage("Reference must not be null");
}
@Test
void logsWhenListenerIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.api.logs(ContainerReference.of("e90e34656806"), null))
.withMessage("Listener must not be null");
.isThrownBy(() -> this.api.logs(ContainerReference.of("e90e34656806"), null))
.withMessage("Listener must not be null");
}
@Test
@@ -478,7 +478,7 @@ class DockerApiTests {
@Test
void waitWhenReferenceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.wait(null))
.withMessage("Reference must not be null");
.withMessage("Reference must not be null");
}
@Test
@@ -493,7 +493,7 @@ class DockerApiTests {
@Test
void removeWhenReferenceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.remove(null, true))
.withMessage("Reference must not be null");
.withMessage("Reference must not be null");
}
@Test
@@ -529,7 +529,7 @@ class DockerApiTests {
@Test
void deleteWhenNameIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.api.delete(null, false))
.withMessage("Name must not be null");
.withMessage("Name must not be null");
}
@Test

View File

@@ -37,11 +37,11 @@ class LogUpdateEventTests {
List<LogUpdateEvent> events = readAll("log-update-event.stream");
assertThat(events).hasSize(7);
assertThat(events.get(0))
.hasToString("Analyzing image '307c032c4ceaa6330b6c02af945a1fe56a8c3c27c28268574b217c1d38b093cf'");
.hasToString("Analyzing image '307c032c4ceaa6330b6c02af945a1fe56a8c3c27c28268574b217c1d38b093cf'");
assertThat(events.get(1))
.hasToString("Writing metadata for uncached layer 'org.cloudfoundry.openjdk:openjdk-jre'");
.hasToString("Writing metadata for uncached layer 'org.cloudfoundry.openjdk:openjdk-jre'");
assertThat(events.get(2))
.hasToString("Using cached launch layer 'org.cloudfoundry.jvmapplication:executable-jar'");
.hasToString("Using cached launch layer 'org.cloudfoundry.jvmapplication:executable-jar'");
}
@Test

View File

@@ -38,13 +38,13 @@ class TotalProgressEventTests {
@Test
void createWhenPercentLessThanZeroThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new TotalProgressEvent(-1))
.withMessage("Percent must be in the range 0 to 100");
.withMessage("Percent must be in the range 0 to 100");
}
@Test
void createWhenEventMoreThanOneHundredThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new TotalProgressEvent(101))
.withMessage("Percent must be in the range 0 to 100");
.withMessage("Percent must be in the range 0 to 100");
}
}

View File

@@ -74,7 +74,7 @@ class CertificateParserTests {
void parseWithInvalidPathWillThrowException() throws URISyntaxException {
Path path = Paths.get(new URI("file:///bad/path/cert.pem"));
assertThatIllegalStateException().isThrownBy(() -> CertificateParser.parse(path))
.withMessageContaining(path.toString());
.withMessageContaining(path.toString());
}
}

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.
@@ -87,7 +87,7 @@ class PrivateKeyParserTests {
void parseWithNonKeyFileWillThrowException() throws IOException {
Path path = this.fileWriter.writeFile("text.pem", "plain text");
assertThatIllegalStateException().isThrownBy(() -> PrivateKeyParser.parse(path))
.withMessageContaining(path.toString());
.withMessageContaining(path.toString());
Files.delete(path);
}
@@ -95,7 +95,7 @@ class PrivateKeyParserTests {
void parseWithInvalidPathWillThrowException() throws URISyntaxException {
Path path = Paths.get(new URI("file:///bad/path/key.pem"));
assertThatIllegalStateException().isThrownBy(() -> PrivateKeyParser.parse(path))
.withMessageContaining(path.toString());
.withMessageContaining(path.toString());
}
@Nested

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.
@@ -35,20 +35,20 @@ class DockerConnectionExceptionTests {
@Test
void createWhenHostIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new DockerConnectionException(null, null))
.withMessage("Host must not be null");
.withMessage("Host must not be null");
}
@Test
void createWhenCauseIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new DockerConnectionException(HOST, null))
.withMessage("Cause must not be null");
.withMessage("Cause must not be null");
}
@Test
void createWithIOException() {
DockerConnectionException exception = new DockerConnectionException(HOST, new IOException("error"));
assertThat(exception.getMessage())
.contains("Connection to the Docker daemon at 'docker://localhost/' failed with error \"error\"");
.contains("Connection to the Docker daemon at 'docker://localhost/' failed with error \"error\"");
}
@Test
@@ -56,7 +56,7 @@ class DockerConnectionExceptionTests {
DockerConnectionException exception = new DockerConnectionException(HOST,
new IOException(new com.sun.jna.LastErrorException("root cause")));
assertThat(exception.getMessage())
.contains("Connection to the Docker daemon at 'docker://localhost/' failed with error \"root cause\"");
.contains("Connection to the Docker daemon at 'docker://localhost/' failed with error \"root cause\"");
}
}

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,15 +56,15 @@ class DockerEngineExceptionTests {
@Test
void createWhenHostIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DockerEngineException(null, null, 404, null, NO_ERRORS, NO_MESSAGE))
.withMessage("Host must not be null");
.isThrownBy(() -> new DockerEngineException(null, null, 404, null, NO_ERRORS, NO_MESSAGE))
.withMessage("Host must not be null");
}
@Test
void createWhenUriIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DockerEngineException(HOST, null, 404, null, NO_ERRORS, NO_MESSAGE))
.withMessage("URI must not be null");
.isThrownBy(() -> new DockerEngineException(HOST, null, 404, null, NO_ERRORS, NO_MESSAGE))
.withMessage("URI must not be null");
}
@Test

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.
@@ -264,10 +264,10 @@ class HttpClientTransportTests {
given(this.entity.getContent()).willReturn(getClass().getResourceAsStream("errors.json"));
given(this.statusLine.getStatusCode()).willReturn(404);
assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri))
.satisfies((ex) -> {
assertThat(ex.getErrors()).hasSize(2);
assertThat(ex.getResponseMessage()).isNull();
});
.satisfies((ex) -> {
assertThat(ex.getErrors()).hasSize(2);
assertThat(ex.getResponseMessage()).isNull();
});
}
@Test
@@ -275,10 +275,10 @@ class HttpClientTransportTests {
givenClientWillReturnResponse();
given(this.statusLine.getStatusCode()).willReturn(500);
assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri))
.satisfies((ex) -> {
assertThat(ex.getErrors()).isNull();
assertThat(ex.getResponseMessage()).isNull();
});
.satisfies((ex) -> {
assertThat(ex.getErrors()).isNull();
assertThat(ex.getResponseMessage()).isNull();
});
}
@Test
@@ -287,10 +287,10 @@ class HttpClientTransportTests {
given(this.entity.getContent()).willReturn(getClass().getResourceAsStream("message.json"));
given(this.statusLine.getStatusCode()).willReturn(500);
assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri))
.satisfies((ex) -> {
assertThat(ex.getErrors()).isNull();
assertThat(ex.getResponseMessage().getMessage()).contains("test message");
});
.satisfies((ex) -> {
assertThat(ex.getErrors()).isNull();
assertThat(ex.getResponseMessage().getMessage()).contains("test message");
});
}
@Test
@@ -299,18 +299,18 @@ class HttpClientTransportTests {
given(this.entity.getContent()).willReturn(this.content);
given(this.statusLine.getStatusCode()).willReturn(500);
assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri))
.satisfies((ex) -> {
assertThat(ex.getErrors()).isNull();
assertThat(ex.getResponseMessage()).isNull();
});
.satisfies((ex) -> {
assertThat(ex.getErrors()).isNull();
assertThat(ex.getResponseMessage()).isNull();
});
}
@Test
void executeWhenClientThrowsIOExceptionRethrowsAsDockerException() throws IOException {
given(this.client.execute(any(HttpHost.class), any(HttpRequest.class)))
.willThrow(new IOException("test IO exception"));
.willThrow(new IOException("test IO exception"));
assertThatExceptionOfType(DockerConnectionException.class).isThrownBy(() -> this.http.get(this.uri))
.satisfies((ex) -> assertThat(ex.getMessage()).contains("test IO exception"));
.satisfies((ex) -> assertThat(ex.getMessage()).contains("test IO exception"));
}
private String writeToString(HttpEntity entity) throws IOException {

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.
@@ -80,7 +80,7 @@ class RemoteHttpClientTransportTests {
SslContextFactory sslContextFactory = mock(SslContextFactory.class);
given(sslContextFactory.forDirectory("/test-cert-path")).willReturn(SSLContext.getDefault());
ResolvedDockerHost dockerHost = ResolvedDockerHost
.from(new DockerHost("tcp://192.168.1.2:2376", true, "/test-cert-path"));
.from(new DockerHost("tcp://192.168.1.2:2376", true, "/test-cert-path"));
RemoteHttpClientTransport transport = RemoteHttpClientTransport.createIfPossible(dockerHost, sslContextFactory);
assertThat(transport.getHost()).satisfies(hostOf("https", "192.168.1.2", 2376));
}
@@ -89,7 +89,7 @@ class RemoteHttpClientTransportTests {
void createIfPossibleWhenTlsVerifyWithMissingCertPathThrowsException() {
ResolvedDockerHost dockerHost = ResolvedDockerHost.from(new DockerHost("tcp://192.168.1.2:2376", true, null));
assertThatIllegalArgumentException().isThrownBy(() -> RemoteHttpClientTransport.createIfPossible(dockerHost))
.withMessageContaining("Docker host TLS verification requires trust material");
.withMessageContaining("Docker host TLS verification requires trust material");
}
private Consumer<HttpHost> hostOf(String scheme, String hostName, int port) {

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.
@@ -37,7 +37,7 @@ class BindingTests {
@Test
void ofWithNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Binding.of(null))
.withMessageContaining("Value must not be null");
.withMessageContaining("Value must not be null");
}
@Test
@@ -49,13 +49,13 @@ class BindingTests {
@Test
void fromWithNullSourceThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Binding.from((String) null, "container-dest"))
.withMessageContaining("Source must not be null");
.withMessageContaining("Source must not be null");
}
@Test
void fromWithNullDestinationThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Binding.from("host-src", null))
.withMessageContaining("Destination must not be null");
.withMessageContaining("Destination must not be null");
}
@Test
@@ -67,7 +67,7 @@ class BindingTests {
@Test
void fromVolumeNameSourceWithNullSourceThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Binding.from((VolumeName) null, "container-dest"))
.withMessageContaining("SourceVolume must not be null");
.withMessageContaining("SourceVolume must not be null");
}
}

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.
@@ -46,7 +46,7 @@ class ContainerConfigTests extends AbstractJsonTests {
void ofWhenUpdateIsNullThrowsException() {
ImageReference imageReference = ImageReference.of("ubuntu:bionic");
assertThatIllegalArgumentException().isThrownBy(() -> ContainerConfig.of(imageReference, null))
.withMessage("Update must not be null");
.withMessage("Update must not be null");
}
@Test

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.
@@ -34,21 +34,21 @@ class ContainerContentTests {
@Test
void ofWhenArchiveIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ContainerContent.of(null))
.withMessage("Archive must not be null");
.withMessage("Archive must not be null");
}
@Test
void ofWhenDestinationPathIsNullThrowsException() {
TarArchive archive = mock(TarArchive.class);
assertThatIllegalArgumentException().isThrownBy(() -> ContainerContent.of(archive, null))
.withMessage("DestinationPath must not be empty");
.withMessage("DestinationPath must not be empty");
}
@Test
void ofWhenDestinationPathIsEmptyThrowsException() {
TarArchive archive = mock(TarArchive.class);
assertThatIllegalArgumentException().isThrownBy(() -> ContainerContent.of(archive, ""))
.withMessage("DestinationPath must not be empty");
.withMessage("DestinationPath must not be empty");
}
@Test

View File

@@ -31,30 +31,30 @@ class ContainerReferenceTests {
@Test
void ofCreatesInstance() {
ContainerReference reference = ContainerReference
.of("92691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
.of("92691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
assertThat(reference).hasToString("92691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
}
@Test
void ofWhenNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ContainerReference.of(null))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test
void ofWhenEmptyThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ContainerReference.of(""))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test
void hashCodeAndEquals() {
ContainerReference r1 = ContainerReference
.of("92691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
.of("92691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
ContainerReference r2 = ContainerReference
.of("92691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
.of("92691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
ContainerReference r3 = ContainerReference
.of("02691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
.of("02691aec176333f7ae890de9aaeeafef11166efcaa3908edf83eb44a5c943781");
assertThat(r1).hasSameHashCodeAs(r2);
assertThat(r1).isEqualTo(r1).isEqualTo(r2).isNotEqualTo(r3);
}

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.
@@ -68,9 +68,9 @@ class ImageConfigTests extends AbstractJsonTests {
void updateWithLabelUpdatesLabels() throws Exception {
ImageConfig imageConfig = getImageConfig();
ImageConfig updatedImageConfig = imageConfig
.copy((update) -> update.withLabel("io.buildpacks.stack.id", "test"));
.copy((update) -> update.withLabel("io.buildpacks.stack.id", "test"));
assertThat(imageConfig.getLabels()).hasSize(4)
.contains(entry("io.buildpacks.stack.id", "org.cloudfoundry.stacks.cflinuxfs3"));
.contains(entry("io.buildpacks.stack.id", "org.cloudfoundry.stacks.cflinuxfs3"));
assertThat(updatedImageConfig.getLabels()).hasSize(4).contains(entry("io.buildpacks.stack.id", "test"));
}

View File

@@ -118,7 +118,7 @@ class ImageNameTests {
@Test
void ofWhenNameIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ImageName.of(null))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test
@@ -129,20 +129,23 @@ class ImageNameTests {
@Test
void ofWhenContainsUppercaseThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ImageName.of("Test"))
.withMessageContaining("Unable to parse name").withMessageContaining("Test");
.withMessageContaining("Unable to parse name")
.withMessageContaining("Test");
}
@Test
void ofWhenNameIncludesTagThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ImageName.of("ubuntu:latest"))
.withMessageContaining("Unable to parse name").withMessageContaining(":latest");
.withMessageContaining("Unable to parse name")
.withMessageContaining(":latest");
}
@Test
void ofWhenNameIncludeDigestThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> ImageName.of("ubuntu@sha256:47bfdb88c3ae13e488167607973b7688f69d9e8c142c2045af343ec199649c09"))
.withMessageContaining("Unable to parse name").withMessageContaining("@sha256:47b");
.withMessageContaining("Unable to parse name")
.withMessageContaining("@sha256:47b");
}
@Test

View File

@@ -115,12 +115,12 @@ class ImageReferenceTests {
@Test
void ofNameAndDigest() {
ImageReference reference = ImageReference
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThat(reference.getDomain()).isEqualTo("docker.io");
assertThat(reference.getName()).isEqualTo("library/ubuntu");
assertThat(reference.getTag()).isNull();
assertThat(reference.getDigest())
.isEqualTo("sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
.isEqualTo("sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThat(reference).hasToString(
"docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
}
@@ -128,25 +128,25 @@ class ImageReferenceTests {
@Test
void ofNameAndTagAndDigest() {
ImageReference reference = ImageReference
.of("ubuntu:bionic@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
.of("ubuntu:bionic@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThat(reference.getDomain()).isEqualTo("docker.io");
assertThat(reference.getName()).isEqualTo("library/ubuntu");
assertThat(reference.getTag()).isEqualTo("bionic");
assertThat(reference.getDigest())
.isEqualTo("sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
.isEqualTo("sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThat(reference).hasToString(
"docker.io/library/ubuntu:bionic@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
}
@Test
void ofCustomDomainAndPortWithTag() {
ImageReference reference = ImageReference.of(
"example.com:8080/canonical/ubuntu:bionic@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
ImageReference reference = ImageReference
.of("example.com:8080/canonical/ubuntu:bionic@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThat(reference.getDomain()).isEqualTo("example.com:8080");
assertThat(reference.getName()).isEqualTo("canonical/ubuntu");
assertThat(reference.getTag()).isEqualTo("bionic");
assertThat(reference.getDigest())
.isEqualTo("sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
.isEqualTo("sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThat(reference).hasToString(
"example.com:8080/canonical/ubuntu:bionic@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
}
@@ -174,9 +174,9 @@ class ImageReferenceTests {
@Test
void ofWhenHasIllegalCharacter() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ImageReference
.of("registry.example.com/example/example-app:1.6.0-dev.2.uncommitted+wip.foo.c75795d"))
.withMessageContaining("Unable to parse image reference");
.isThrownBy(() -> ImageReference
.of("registry.example.com/example/example-app:1.6.0-dev.2.uncommitted+wip.foo.c75795d"))
.withMessageContaining("Unable to parse image reference");
}
@Test
@@ -219,15 +219,16 @@ class ImageReferenceTests {
@Test
void randomWherePrefixIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ImageReference.random(null))
.withMessage("Prefix must not be null");
.withMessage("Prefix must not be null");
}
@Test
void inTaggedFormWhenHasDigestThrowsException() {
ImageReference reference = ImageReference
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThatIllegalStateException().isThrownBy(() -> reference.inTaggedForm()).withMessage(
"Image reference 'docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d' cannot contain a digest");
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThatIllegalStateException().isThrownBy(() -> reference.inTaggedForm())
.withMessage(
"Image reference 'docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d' cannot contain a digest");
}
@Test
@@ -245,7 +246,7 @@ class ImageReferenceTests {
@Test
void inTaggedOrDigestFormWhenHasDigestUsesDigest() {
ImageReference reference = ImageReference
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThat(reference.inTaggedOrDigestForm()).hasToString(
"docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
}

View File

@@ -56,9 +56,9 @@ class ImageTests extends AbstractJsonTests {
List<LayerId> layers = image.getLayers();
assertThat(layers).hasSize(46);
assertThat(layers.get(0))
.hasToString("sha256:733a8e5ce32984099ef675fce04730f6e2a6dcfdf5bd292fea01a8f936265342");
.hasToString("sha256:733a8e5ce32984099ef675fce04730f6e2a6dcfdf5bd292fea01a8f936265342");
assertThat(layers.get(45))
.hasToString("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef");
.hasToString("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef");
}
@Test

View File

@@ -52,7 +52,7 @@ class LayerIdTests {
@Test
void ofWhenValueIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> LayerId.of((String) null))
.withMessage("Value must not be empty");
.withMessage("Value must not be empty");
}
@Test
@@ -80,13 +80,13 @@ class LayerIdTests {
@Test
void ofSha256DigestWhenNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> LayerId.ofSha256Digest((byte[]) null))
.withMessage("Digest must not be null");
.withMessage("Digest must not be null");
}
@Test
void ofSha256DigestWhenWrongLengthThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> LayerId.ofSha256Digest(new byte[31]))
.withMessage("Digest must be exactly 32 bytes");
.withMessage("Digest must be exactly 32 bytes");
}
}

View File

@@ -40,13 +40,13 @@ class LayerTests {
@Test
void ofWhenLayoutIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Layer.of((IOConsumer<Layout>) null))
.withMessage("Layout must not be null");
.withMessage("Layout must not be null");
}
@Test
void fromTarArchiveWhenTarArchiveIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Layer.fromTarArchive(null))
.withMessage("TarArchive must not be null");
.withMessage("TarArchive must not be null");
}
@Test
@@ -56,7 +56,7 @@ class LayerTests {
layout.file("/directory/file", Owner.ROOT, Content.of("test"));
});
assertThat(layer.getId())
.hasToString("sha256:d03a34f73804698c875eb56ff694fc2fceccc69b645e4adceb004ed13588613b");
.hasToString("sha256:d03a34f73804698c875eb56ff694fc2fceccc69b645e4adceb004ed13588613b");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
layer.writeTo(outputStream);
try (TarArchiveInputStream tarStream = new TarArchiveInputStream(

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.
@@ -31,7 +31,7 @@ class RandomStringTests {
@Test
void generateWhenPrefixIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> RandomString.generate(null, 10))
.withMessage("Prefix must not be null");
.withMessage("Prefix must not be null");
}
@Test

View File

@@ -31,7 +31,7 @@ class VolumeNameTests {
@Test
void randomWhenPrefixIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.random(null))
.withMessage("Prefix must not be null");
.withMessage("Prefix must not be null");
}
@Test
@@ -57,25 +57,25 @@ class VolumeNameTests {
@Test
void basedOnWhenSourceIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn(null, "prefix", "suffix", 6))
.withMessage("Source must not be null");
.withMessage("Source must not be null");
}
@Test
void basedOnWhenNameExtractorIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn("test", null, "prefix", "suffix", 6))
.withMessage("NameExtractor must not be null");
.withMessage("NameExtractor must not be null");
}
@Test
void basedOnWhenPrefixIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn("test", null, "suffix", 6))
.withMessage("Prefix must not be null");
.withMessage("Prefix must not be null");
}
@Test
void basedOnWhenSuffixIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn("test", "prefix", null, 6))
.withMessage("Suffix must not be null");
.withMessage("Suffix must not be null");
}
@Test
@@ -87,13 +87,13 @@ class VolumeNameTests {
@Test
void basedOnWhenSizeIsTooBigThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn("name", "prefix", "suffix", 33))
.withMessage("DigestLength must be less than or equal to 32");
.withMessage("DigestLength must be less than or equal to 32");
}
@Test
void ofWhenValueIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.of(null))
.withMessage("Value must not be null");
.withMessage("Value must not be null");
}
@Test

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.
@@ -37,7 +37,7 @@ class ContentTests {
@Test
void ofWhenStreamIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Content.of(1, (IOSupplier<InputStream>) null))
.withMessage("Supplier must not be null");
.withMessage("Supplier must not be null");
}
@Test
@@ -51,7 +51,7 @@ class ContentTests {
@Test
void ofWhenStringIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Content.of((String) null))
.withMessage("String must not be null");
.withMessage("String must not be null");
}
@Test
@@ -63,7 +63,7 @@ class ContentTests {
@Test
void ofWhenBytesIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> Content.of((byte[]) null))
.withMessage("Bytes must not be null");
.withMessage("Bytes must not be null");
}
@Test

View File

@@ -51,7 +51,7 @@ class FilePermissionsTests {
@DisabledOnOs(OS.WINDOWS)
void umaskForPath() throws IOException {
FileAttribute<Set<PosixFilePermission>> fileAttribute = PosixFilePermissions
.asFileAttribute(PosixFilePermissions.fromString("rw-r-----"));
.asFileAttribute(PosixFilePermissions.fromString("rw-r-----"));
Path tempFile = Files.createTempFile(this.tempDir, "umask", null, fileAttribute);
assertThat(FilePermissions.umaskForPath(tempFile)).isEqualTo(0640);
}
@@ -60,7 +60,7 @@ class FilePermissionsTests {
@DisabledOnOs(OS.WINDOWS)
void umaskForPathWithNonExistentFile() {
assertThatIOException()
.isThrownBy(() -> FilePermissions.umaskForPath(Paths.get(this.tempDir.toString(), "does-not-exist")));
.isThrownBy(() -> FilePermissions.umaskForPath(Paths.get(this.tempDir.toString(), "does-not-exist")));
}
@Test
@@ -68,7 +68,7 @@ class FilePermissionsTests {
void umaskForPathOnWindowsFails() throws IOException {
Path tempFile = Files.createTempFile("umask", null);
assertThatIllegalStateException().isThrownBy(() -> FilePermissions.umaskForPath(tempFile))
.withMessageContaining("Unsupported file type for retrieving Posix attributes");
.withMessageContaining("Unsupported file type for retrieving Posix attributes");
}
@Test

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.
@@ -39,19 +39,19 @@ class InspectedContentTests {
@Test
void ofWhenInputStreamThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> InspectedContent.of((InputStream) null))
.withMessage("InputStream must not be null");
.withMessage("InputStream must not be null");
}
@Test
void ofWhenContentIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> InspectedContent.of((Content) null))
.withMessage("Content must not be null");
.withMessage("Content must not be null");
}
@Test
void ofWhenConsumerIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> InspectedContent.of((IOConsumer<OutputStream>) null))
.withMessage("Writer must not be null");
.withMessage("Writer must not be null");
}
@Test
@@ -85,9 +85,9 @@ class InspectedContentTests {
InputStream inputStream = new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8));
MessageDigest digest = MessageDigest.getInstance("SHA-256");
InspectedContent.of(inputStream, digest::update);
assertThat(digest.digest()).inHexadecimal().contains(0x9f, 0x86, 0xd0, 0x81, 0x88, 0x4c, 0x7d, 0x65, 0x9a, 0x2f,
0xea, 0xa0, 0xc5, 0x5a, 0xd0, 0x15, 0xa3, 0xbf, 0x4f, 0x1b, 0x2b, 0x0b, 0x82, 0x2c, 0xd1, 0x5d, 0x6c,
0x15, 0xb0, 0xf0, 0x0a, 0x08);
assertThat(digest.digest()).inHexadecimal()
.contains(0x9f, 0x86, 0xd0, 0x81, 0x88, 0x4c, 0x7d, 0x65, 0x9a, 0x2f, 0xea, 0xa0, 0xc5, 0x5a, 0xd0, 0x15,
0xa3, 0xbf, 0x4f, 0x1b, 0x2b, 0x0b, 0x82, 0x2c, 0xd1, 0x5d, 0x6c, 0x15, 0xb0, 0xf0, 0x0a, 0x08);
}
private byte[] readBytes(InspectedContent content) throws IOException {

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 ZipFileTarArchiveTests {
@Test
void createWhenZipIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new ZipFileTarArchive(null, Owner.ROOT))
.withMessage("Zip must not be null");
.withMessage("Zip must not be null");
}
@Test
@@ -54,7 +54,7 @@ class ZipFileTarArchiveTests {
File file = new File(this.tempDir, "test.zip");
writeTestZip(file);
assertThatIllegalArgumentException().isThrownBy(() -> new ZipFileTarArchive(file, null))
.withMessage("Owner must not be null");
.withMessage("Owner must not be null");
}
@Test

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 @@ public abstract class AbstractJsonTests {
protected final String getContentAsString(String name) {
return new BufferedReader(new InputStreamReader(getContent(name), StandardCharsets.UTF_8)).lines()
.collect(Collectors.joining("\n"));
.collect(Collectors.joining("\n"));
}
}

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.
@@ -45,7 +45,7 @@ class JsonStreamTests extends AbstractJsonTests {
this.jsonStream.get(getContent("stream.json"), result::add);
assertThat(result).hasSize(595);
assertThat(result.get(594).toString())
.contains("Status: Downloaded newer image for paketo-buildpacks/cnb:base");
.contains("Status: Downloaded newer image for paketo-buildpacks/cnb:base");
}
@Test
@@ -55,7 +55,7 @@ class JsonStreamTests extends AbstractJsonTests {
assertThat(result).hasSize(595);
assertThat(result.get(1).getId()).isEqualTo("5667fdb72017");
assertThat(result.get(594).getStatus())
.isEqualTo("Status: Downloaded newer image for paketo-buildpacks/cnb:base");
.isEqualTo("Status: Downloaded newer image for paketo-buildpacks/cnb:base");
}
/**

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.
@@ -38,13 +38,13 @@ class SharedObjectMapperTests {
assertThat(mapper).isNotNull();
assertThat(mapper.getRegisteredModuleIds()).contains(new ParameterNamesModule().getTypeId());
assertThat(SerializationFeature.INDENT_OUTPUT
.enabledIn(mapper.getSerializationConfig().getSerializationFeatures())).isTrue();
.enabledIn(mapper.getSerializationConfig().getSerializationFeatures())).isTrue();
assertThat(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
.enabledIn(mapper.getDeserializationConfig().getDeserializationFeatures())).isFalse();
.enabledIn(mapper.getDeserializationConfig().getDeserializationFeatures())).isFalse();
assertThat(mapper.getSerializationConfig().getPropertyNamingStrategy())
.isEqualTo(PropertyNamingStrategies.LOWER_CAMEL_CASE);
.isEqualTo(PropertyNamingStrategies.LOWER_CAMEL_CASE);
assertThat(mapper.getDeserializationConfig().getPropertyNamingStrategy())
.isEqualTo(PropertyNamingStrategies.LOWER_CAMEL_CASE);
.isEqualTo(PropertyNamingStrategies.LOWER_CAMEL_CASE);
}
}

View File

@@ -132,9 +132,9 @@ public final class CommandLineInvoker {
public Invocation(Process process) {
this.process = process;
this.streamReaders
.add(new Thread(new StreamReadingRunnable(this.process.getErrorStream(), this.err, this.combined)));
.add(new Thread(new StreamReadingRunnable(this.process.getErrorStream(), this.err, this.combined)));
this.streamReaders
.add(new Thread(new StreamReadingRunnable(this.process.getInputStream(), this.out, this.combined)));
.add(new Thread(new StreamReadingRunnable(this.process.getInputStream(), this.out, this.combined)));
for (Thread streamReader : this.streamReaders) {
streamReader.start();
}

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.
@@ -40,7 +40,7 @@ import org.springframework.util.StringUtils;
public class CommandRunner implements Iterable<Command> {
private static final Set<CommandException.Option> NO_EXCEPTION_OPTIONS = EnumSet
.noneOf(CommandException.Option.class);
.noneOf(CommandException.Option.class);
private final String name;

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.
@@ -70,8 +70,8 @@ public class EncodePasswordCommand extends OptionParsingCommand {
@Override
public Collection<HelpExample> getExamples() {
List<HelpExample> examples = new ArrayList<>();
examples.add(
new HelpExample("To encode a password with the default encoder", "spring encodepassword mypassword"));
examples
.add(new HelpExample("To encode a password with the default encoder", "spring encodepassword mypassword"));
examples.add(new HelpExample("To encode a password with pbkdf2", "spring encodepassword -a pbkdf2 mypassword"));
return examples;
}
@@ -83,7 +83,7 @@ public class EncodePasswordCommand extends OptionParsingCommand {
@Override
protected void options() {
this.algorithm = option(Arrays.asList("algorithm", "a"), "The algorithm to use").withRequiredArg()
.defaultsTo("default");
.defaultsTo("default");
}
@Override

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.
@@ -139,7 +139,7 @@ public class InitCommand extends OptionParsingCommand {
@Override
protected void options() {
this.target = option(Arrays.asList("target"), "URL of the service to use").withRequiredArg()
.defaultsTo(ProjectGenerationRequest.DEFAULT_SERVICE_URL);
.defaultsTo(ProjectGenerationRequest.DEFAULT_SERVICE_URL);
this.listCapabilities = option(Arrays.asList("list"),
"List the capabilities of the service. Use it to discover the "
+ "dependencies and the types that are available");
@@ -149,33 +149,37 @@ public class InitCommand extends OptionParsingCommand {
private void projectGenerationOptions() {
this.groupId = option(Arrays.asList("group-id", "g"), "Project coordinates (for example 'org.test')")
.withRequiredArg();
.withRequiredArg();
this.artifactId = option(Arrays.asList("artifact-id", "a"),
"Project coordinates; infer archive name (for example 'test')").withRequiredArg();
"Project coordinates; infer archive name (for example 'test')")
.withRequiredArg();
this.version = option(Arrays.asList("version", "v"), "Project version (for example '0.0.1-SNAPSHOT')")
.withRequiredArg();
.withRequiredArg();
this.name = option(Arrays.asList("name", "n"), "Project name; infer application name").withRequiredArg();
this.description = option("description", "Project description").withRequiredArg();
this.packageName = option(Arrays.asList("package-name"), "Package name").withRequiredArg();
this.type = option(Arrays.asList("type", "t"),
"Project type. Not normally needed if you use --build "
+ "and/or --format. Check the capabilities of the service (--list) for more details")
.withRequiredArg();
.withRequiredArg();
this.packaging = option(Arrays.asList("packaging", "p"), "Project packaging (for example 'jar')")
.withRequiredArg();
.withRequiredArg();
this.build = option("build", "Build system to use (for example 'maven' or 'gradle')").withRequiredArg()
.defaultsTo("maven");
.defaultsTo("maven");
this.format = option("format", "Format of the generated content (for example 'build' for a build file, "
+ "'project' for a project archive)").withRequiredArg().defaultsTo("project");
+ "'project' for a project archive)")
.withRequiredArg()
.defaultsTo("project");
this.javaVersion = option(Arrays.asList("java-version", "j"), "Language level (for example '1.8')")
.withRequiredArg();
.withRequiredArg();
this.language = option(Arrays.asList("language", "l"), "Programming language (for example 'java')")
.withRequiredArg();
.withRequiredArg();
this.bootVersion = option(Arrays.asList("boot-version", "b"),
"Spring Boot version (for example '1.2.0.RELEASE')").withRequiredArg();
"Spring Boot version (for example '1.2.0.RELEASE')")
.withRequiredArg();
this.dependencies = option(Arrays.asList("dependencies", "d"),
"Comma-separated list of dependency identifiers to include in the generated project")
.withRequiredArg();
.withRequiredArg();
}
private void otherOptions() {

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.
@@ -152,7 +152,7 @@ public class OptionHandler {
@Override
public String format(Map<String, ? extends OptionDescriptor> options) {
Comparator<OptionDescriptor> comparator = Comparator
.comparing((optionDescriptor) -> optionDescriptor.options().iterator().next());
.comparing((optionDescriptor) -> optionDescriptor.options().iterator().next());
Set<OptionDescriptor> sorted = new TreeSet<>(comparator);
sorted.addAll(options.values());
for (OptionDescriptor descriptor : sorted) {

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.
@@ -114,7 +114,7 @@ public class Shell {
this.consoleReader.setBellEnabled(false);
this.consoleReader.setExpandEvents(false);
this.consoleReader
.addCompleter(new CommandCompleter(this.consoleReader, this.argumentDelimiter, this.commandRunner));
.addCompleter(new CommandCompleter(this.consoleReader, this.argumentDelimiter, this.commandRunner));
this.consoleReader.setCompletionHandler(new CandidateListCompletionHandler());
}

View File

@@ -160,7 +160,7 @@ class CommandRunnerTests {
@Test
void exceptionMessages() {
assertThat(new NoSuchCommandException("name").getMessage())
.isEqualTo("'name' is not a valid command. See 'help'.");
.isEqualTo("'name' is not a valid command. See 'help'.");
}
@Test
@@ -172,13 +172,13 @@ class CommandRunnerTests {
@Test
void helpNoCommand() {
assertThatExceptionOfType(NoHelpCommandArgumentsException.class)
.isThrownBy(() -> this.commandRunner.run("help"));
.isThrownBy(() -> this.commandRunner.run("help"));
}
@Test
void helpUnknownCommand() {
assertThatExceptionOfType(NoSuchCommandException.class)
.isThrownBy(() -> this.commandRunner.run("help", "missing"));
.isThrownBy(() -> this.commandRunner.run("help", "missing"));
}
private enum Call {

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 @@ class EncodePasswordCommandTests {
then(this.log).should().info(this.message.capture());
assertThat(this.message.getValue()).startsWith("{bcrypt}");
assertThat(PasswordEncoderFactories.createDelegatingPasswordEncoder().matches("boot", this.message.getValue()))
.isTrue();
.isTrue();
assertThat(status).isEqualTo(ExitStatus.OK);
}
@@ -84,7 +84,7 @@ class EncodePasswordCommandTests {
then(this.log).should().info(this.message.capture());
assertThat(this.message.getValue()).doesNotStartWith("{");
assertThat(Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8().matches("boot", this.message.getValue()))
.isTrue();
.isTrue();
assertThat(status).isEqualTo(ExitStatus.OK);
}

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.
@@ -77,7 +77,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
ProjectGenerationRequest request = new ProjectGenerationRequest();
request.getDependencies().add("foo:bar");
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining(jsonMessage);
.withMessageContaining(jsonMessage);
}
@Test
@@ -85,7 +85,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
mockProjectGenerationError(400, null);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining("unexpected 400 error");
.withMessageContaining("unexpected 400 error");
}
@Test
@@ -96,7 +96,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining("No content received from server");
.withMessageContaining("No content received from server");
}
@Test
@@ -105,7 +105,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
mockMetadataGetError(500, jsonMessage);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining(jsonMessage);
.withMessageContaining(jsonMessage);
}
@Test
@@ -116,7 +116,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining("Invalid content received from server");
.withMessageContaining("Invalid content received from server");
}
@Test
@@ -126,7 +126,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining("No content received from server");
.withMessageContaining("No content received from server");
}
private ProjectGenerationResponse generateProject(ProjectGenerationRequest request,

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.
@@ -57,21 +57,21 @@ class ProjectGenerationRequestTests {
this.request.setServiceUrl(customServerUrl);
this.request.getDependencies().add("security");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(new URI(customServerUrl + "/starter.zip?dependencies=security&type=test-type"));
.isEqualTo(new URI(customServerUrl + "/starter.zip?dependencies=security&type=test-type"));
}
@Test
void customBootVersion() {
this.request.setBootVersion("1.2.0.RELEASE");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?type=test-type&bootVersion=1.2.0.RELEASE"));
.isEqualTo(createDefaultUrl("?type=test-type&bootVersion=1.2.0.RELEASE"));
}
@Test
void singleDependency() {
this.request.getDependencies().add("web");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?dependencies=web&type=test-type"));
.isEqualTo(createDefaultUrl("?dependencies=web&type=test-type"));
}
@Test
@@ -79,21 +79,21 @@ class ProjectGenerationRequestTests {
this.request.getDependencies().add("web");
this.request.getDependencies().add("data-jpa");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?dependencies=web%2Cdata-jpa&type=test-type"));
.isEqualTo(createDefaultUrl("?dependencies=web%2Cdata-jpa&type=test-type"));
}
@Test
void customJavaVersion() {
this.request.setJavaVersion("1.8");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?type=test-type&javaVersion=1.8"));
.isEqualTo(createDefaultUrl("?type=test-type&javaVersion=1.8"));
}
@Test
void customPackageName() {
this.request.setPackageName("demo.foo");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?packageName=demo.foo&type=test-type"));
.isEqualTo(createDefaultUrl("?packageName=demo.foo&type=test-type"));
}
@Test
@@ -110,14 +110,14 @@ class ProjectGenerationRequestTests {
void customPackaging() {
this.request.setPackaging("war");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?type=test-type&packaging=war"));
.isEqualTo(createDefaultUrl("?type=test-type&packaging=war"));
}
@Test
void customLanguage() {
this.request.setLanguage("groovy");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?type=test-type&language=groovy"));
.isEqualTo(createDefaultUrl("?type=test-type&language=groovy"));
}
@Test
@@ -127,29 +127,29 @@ class ProjectGenerationRequestTests {
this.request.setVersion("1.0.1-SNAPSHOT");
this.request.setDescription("Spring Boot Test");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?groupId=org.acme&artifactId=sample&version=1.0.1-SNAPSHOT"
+ "&description=Spring+Boot+Test&type=test-type"));
.isEqualTo(createDefaultUrl("?groupId=org.acme&artifactId=sample&version=1.0.1-SNAPSHOT"
+ "&description=Spring+Boot+Test&type=test-type"));
}
@Test
void outputCustomizeArtifactId() {
this.request.setOutput("my-project");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?artifactId=my-project&type=test-type"));
.isEqualTo(createDefaultUrl("?artifactId=my-project&type=test-type"));
}
@Test
void outputArchiveCustomizeArtifactId() {
this.request.setOutput("my-project.zip");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?artifactId=my-project&type=test-type"));
.isEqualTo(createDefaultUrl("?artifactId=my-project&type=test-type"));
}
@Test
void outputArchiveWithDotsCustomizeArtifactId() {
this.request.setOutput("my.nice.project.zip");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?artifactId=my.nice.project&type=test-type"));
.isEqualTo(createDefaultUrl("?artifactId=my.nice.project&type=test-type"));
}
@Test
@@ -157,7 +157,7 @@ class ProjectGenerationRequestTests {
this.request.setOutput("my-project");
this.request.setArtifactId("my-id");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?artifactId=my-id&type=test-type"));
.isEqualTo(createDefaultUrl("?artifactId=my-id&type=test-type"));
}
@Test
@@ -165,7 +165,7 @@ class ProjectGenerationRequestTests {
InitializrServiceMetadata metadata = readMetadata();
setBuildAndFormat("does-not-exist", null);
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.request.generateUrl(metadata))
.withMessageContaining("does-not-exist");
.withMessageContaining("does-not-exist");
}
@Test
@@ -173,7 +173,8 @@ class ProjectGenerationRequestTests {
InitializrServiceMetadata metadata = readMetadata("types-conflict");
setBuildAndFormat("gradle", null);
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.request.generateUrl(metadata))
.withMessageContaining("gradle-project").withMessageContaining("gradle-project-2");
.withMessageContaining("gradle-project")
.withMessageContaining("gradle-project-2");
}
@Test
@@ -195,14 +196,14 @@ class ProjectGenerationRequestTests {
void invalidType() {
this.request.setType("does-not-exist");
assertThatExceptionOfType(ReportableException.class)
.isThrownBy(() -> this.request.generateUrl(createDefaultMetadata()));
.isThrownBy(() -> this.request.generateUrl(createDefaultMetadata()));
}
@Test
void noTypeAndNoDefault() {
assertThatExceptionOfType(ReportableException.class)
.isThrownBy(() -> this.request.generateUrl(readMetadata("types-conflict")))
.withMessageContaining("no default is defined");
.isThrownBy(() -> this.request.generateUrl(readMetadata("types-conflict")))
.withMessageContaining("no default is defined");
}
private static URI createUrl(String actionAndParam) {

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.
@@ -52,9 +52,10 @@ class RawConfigurationMetadata {
return null;
}
return this.sources.stream()
.filter((candidate) -> item.getSourceType().equals(candidate.getType())
&& item.getId().startsWith(candidate.getGroupId()))
.max(Comparator.comparingInt((candidate) -> candidate.getGroupId().length())).orElse(null);
.filter((candidate) -> item.getSourceType().equals(candidate.getType())
&& item.getId().startsWith(candidate.getGroupId()))
.max(Comparator.comparingInt((candidate) -> candidate.getGroupId().length()))
.orElse(null);
}
List<ConfigurationMetadataItem> getItems() {

View File

@@ -36,7 +36,7 @@ class ConfigurationMetadataRepositoryJsonBuilderTests extends AbstractConfigurat
@Test
void nullResource() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ConfigurationMetadataRepositoryJsonBuilder.create().withJsonResource(null));
.isThrownBy(() -> ConfigurationMetadataRepositoryJsonBuilder.create().withJsonResource(null));
}
@Test
@@ -105,7 +105,7 @@ class ConfigurationMetadataRepositoryJsonBuilderTests extends AbstractConfigurat
assertThat(group.getSources().get("org.acme.Foo2").getProperties()).containsOnlyKeys("spring.foo.enabled",
"spring.foo.type");
assertThat(group.getSources().get("org.springframework.boot.FooProperties").getProperties())
.containsOnlyKeys("spring.foo.name", "spring.foo.counter");
.containsOnlyKeys("spring.foo.name", "spring.foo.counter");
}
}
@@ -123,7 +123,7 @@ class ConfigurationMetadataRepositoryJsonBuilderTests extends AbstractConfigurat
assertThat(group.getSources().get("org.acme.Foo").getProperties()).containsOnlyKeys("spring.foo.name",
"spring.foo.description", "spring.foo.enabled", "spring.foo.type");
assertThat(group.getSources().get("org.springframework.boot.FooProperties").getProperties())
.containsOnlyKeys("spring.foo.name", "spring.foo.counter");
.containsOnlyKeys("spring.foo.name", "spring.foo.counter");
}
}

View File

@@ -94,7 +94,7 @@ class JsonReaderTests extends AbstractConfigurationMetadataTests {
ValueHint valueHint = hint.getValueHints().get(0);
assertThat(valueHint.getValue()).isEqualTo(42);
assertThat(valueHint.getDescription())
.isEqualTo("Because that's the answer to any question, choose it. \nReally.");
.isEqualTo("Because that's the answer to any question, choose it. \nReally.");
assertThat(valueHint.getShortDescription()).isEqualTo("Because that's the answer to any question, choose it.");
assertThat(hint.getValueProviders()).hasSize(1);
ValueProvider valueProvider = hint.getValueProviders().get(0);

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.
@@ -40,14 +40,14 @@ class SentenceExtractorTests {
@Test
void extractFirstSentenceNewLineBeforeDot() {
String sentence = this.extractor
.getFirstSentence("My short" + NEW_LINE + "description." + NEW_LINE + "More stuff.");
.getFirstSentence("My short" + NEW_LINE + "description." + NEW_LINE + "More stuff.");
assertThat(sentence).isEqualTo("My short description.");
}
@Test
void extractFirstSentenceNewLineBeforeDotWithSpaces() {
String sentence = this.extractor
.getFirstSentence("My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff.");
.getFirstSentence("My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff.");
assertThat(sentence).isEqualTo("My short description.");
}

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.
@@ -103,7 +103,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
static final String AUTO_CONFIGURATION_ANNOTATION = "org.springframework.boot.autoconfigure.AutoConfiguration";
private static final Set<String> SUPPORTED_OPTIONS = Collections
.unmodifiableSet(Collections.singleton(ADDITIONAL_METADATA_LOCATIONS_OPTION));
.unmodifiableSet(Collections.singleton(ADDITIONAL_METADATA_LOCATIONS_OPTION));
private MetadataStore metadataStore;
@@ -241,8 +241,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
this.metadataEnv.getTypeUtils().getQualifiedName(element.getEnclosingElement()),
element.toString());
if (this.metadataCollector.hasSimilarGroup(group)) {
this.processingEnv.getMessager().printMessage(Kind.ERROR,
"Duplicate @ConfigurationProperties definition for prefix '" + prefix + "'", element);
this.processingEnv.getMessager()
.printMessage(Kind.ERROR,
"Duplicate @ConfigurationProperties definition for prefix '" + prefix + "'", element);
}
else {
this.metadataCollector.add(group);
@@ -260,7 +261,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
this.metadataCollector.add(descriptor.resolveItemMetadata(prefix, this.metadataEnv));
if (descriptor.isNested(this.metadataEnv)) {
TypeElement nestedTypeElement = (TypeElement) this.metadataEnv.getTypeUtils()
.asElement(descriptor.getType());
.asElement(descriptor.getType());
String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, descriptor.getName());
processTypeElement(nestedPrefix, nestedTypeElement, source, seen);
}

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.
@@ -275,7 +275,7 @@ class MetadataGenerationEnvironment {
Map<String, Object> getAnnotationElementValues(AnnotationMirror annotation) {
Map<String, Object> values = new LinkedHashMap<>();
annotation.getElementValues()
.forEach((name, value) -> values.put(name.getSimpleName().toString(), getAnnotationValue(value)));
.forEach((name, value) -> values.put(name.getSimpleName().toString(), getAnnotationValue(value)));
return values;
}
@@ -306,8 +306,10 @@ class MetadataGenerationEnvironment {
}
Set<TypeElement> getEndpointAnnotationElements() {
return this.endpointAnnotations.stream().map(this.elements::getTypeElement).filter(Objects::nonNull)
.collect(Collectors.toSet());
return this.endpointAnnotations.stream()
.map(this.elements::getTypeElement)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}
AnnotationMirror getReadOperationAnnotation(Element element) {

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.
@@ -100,8 +100,8 @@ public class MetadataStore {
private InputStream getAdditionalMetadataStream() throws IOException {
// Most build systems will have copied the file to the class output location
FileObject fileObject = this.environment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "",
ADDITIONAL_METADATA_PATH);
FileObject fileObject = this.environment.getFiler()
.getResource(StandardLocation.CLASS_OUTPUT, "", ADDITIONAL_METADATA_PATH);
InputStream inputStream = getMetadataStream(fileObject);
if (inputStream != null) {
return inputStream;
@@ -129,7 +129,7 @@ public class MetadataStore {
return standardLocation;
}
String locations = this.environment.getOptions()
.get(ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION);
.get(ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION);
if (locations != null) {
for (String location : locations.split(",")) {
File candidate = new File(location, ADDITIONAL_METADATA_PATH);

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.
@@ -234,7 +234,8 @@ class TypeUtils {
if (type.getKind() == TypeKind.DECLARED) {
DeclaredType declaredType = (DeclaredType) type;
DeclaredType freshType = (DeclaredType) this.env.getElementUtils()
.getTypeElement(this.types.asElement(type).toString()).asType();
.getTypeElement(this.types.asElement(type).toString())
.asType();
List<? extends TypeMirror> arguments = declaredType.getTypeArguments();
for (int i = 0; i < arguments.size(); i++) {
TypeMirror specificType = arguments.get(i);
@@ -267,9 +268,12 @@ class TypeUtils {
}
StringBuilder name = new StringBuilder();
name.append(qualifiedName);
name.append("<").append(
type.getTypeArguments().stream().map((t) -> visit(t, descriptor)).collect(Collectors.joining(",")))
.append(">");
name.append("<")
.append(type.getTypeArguments()
.stream()
.map((t) -> visit(t, descriptor))
.collect(Collectors.joining(",")))
.append(">");
return name.toString();
}
@@ -365,14 +369,19 @@ class TypeUtils {
}
TypeMirror resolveGeneric(String parameterName) {
return this.generics.entrySet().stream().filter((e) -> getParameterName(e.getKey()).equals(parameterName))
.findFirst().map(Entry::getValue).orElse(null);
return this.generics.entrySet()
.stream()
.filter((e) -> getParameterName(e.getKey()).equals(parameterName))
.findFirst()
.map(Entry::getValue)
.orElse(null);
}
private void registerIfNecessary(TypeMirror variable, TypeMirror resolution) {
if (variable instanceof TypeVariable typeVariable) {
if (this.generics.keySet().stream()
.noneMatch((candidate) -> getParameterName(candidate).equals(getParameterName(typeVariable)))) {
if (this.generics.keySet()
.stream()
.noneMatch((candidate) -> getParameterName(candidate).equals(getParameterName(typeVariable)))) {
this.generics.put(typeVariable, resolution);
}
}

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.
@@ -38,8 +38,11 @@ class JsonConverter {
JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) throws Exception {
JSONArray jsonArray = new JSONArray();
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.isOfItemType(itemType))
.sorted(ITEM_COMPARATOR).toList();
List<ItemMetadata> items = metadata.getItems()
.stream()
.filter((item) -> item.isOfItemType(itemType))
.sorted(ITEM_COMPARATOR)
.toList();
for (ItemMetadata item : items) {
if (item.isOfItemType(itemType)) {
jsonArray.put(toJsonObject(item));
@@ -160,11 +163,11 @@ class JsonConverter {
private static class ItemMetadataComparator implements Comparator<ItemMetadata> {
private static final Comparator<ItemMetadata> GROUP = Comparator.comparing(ItemMetadata::getName)
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
private static final Comparator<ItemMetadata> ITEM = Comparator.comparing(ItemMetadataComparator::isDeprecated)
.thenComparing(ItemMetadata::getName)
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
.thenComparing(ItemMetadata::getName)
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
@Override
public int compare(ItemMetadata o1, ItemMetadata o2) {

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.
@@ -43,9 +43,10 @@ public abstract class AbstractMetadataGenerationTests {
}
protected ConfigurationMetadata compile(String additionalMetadata, Class<?> type, Class<?>... types) {
TestCompiler compiler = TestCompiler.forSystem().withSources(sourceFilesOf(type))
.withSources(sourceFilesOf(types))
.withResources(ResourceFile.of(ADDITIONAL_METADATA_FILE, additionalMetadata));
TestCompiler compiler = TestCompiler.forSystem()
.withSources(sourceFilesOf(type))
.withSources(sourceFilesOf(types))
.withResources(ResourceFile.of(ADDITIONAL_METADATA_FILE, additionalMetadata));
return compile(compiler);
}

View File

@@ -79,15 +79,15 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
@Test
void supportedAnnotations() {
assertThat(new ConfigurationMetadataAnnotationProcessor().getSupportedAnnotationTypes())
.containsExactlyInAnyOrder("org.springframework.boot.autoconfigure.AutoConfiguration",
"org.springframework.boot.context.properties.ConfigurationProperties",
"org.springframework.context.annotation.Configuration",
"org.springframework.boot.actuate.endpoint.annotation.Endpoint",
"org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpoint",
"org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint",
"org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint",
"org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint",
"org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint");
.containsExactlyInAnyOrder("org.springframework.boot.autoconfigure.AutoConfiguration",
"org.springframework.boot.context.properties.ConfigurationProperties",
"org.springframework.context.annotation.Configuration",
"org.springframework.boot.actuate.endpoint.annotation.Endpoint",
"org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpoint",
"org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint",
"org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint",
"org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint",
"org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint");
}
@Test
@@ -101,10 +101,15 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(SimpleProperties.class);
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimpleProperties.class));
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
.withDefaultValue("boot").withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).withDefaultValue(false)
.fromSource(SimpleProperties.class).withDescription("A simple flag.").withDeprecation(null, null));
.fromSource(SimpleProperties.class)
.withDescription("The name of this simple properties.")
.withDefaultValue("boot")
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(SimpleProperties.class)
.withDescription("A simple flag.")
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.counter"));
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.size"));
@@ -115,7 +120,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(SimplePrefixValueProperties.class);
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimplePrefixValueProperties.class));
assertThat(metadata)
.has(Metadata.withProperty("simple.name", String.class).fromSource(SimplePrefixValueProperties.class));
.has(Metadata.withProperty("simple.name", String.class).fromSource(SimplePrefixValueProperties.class));
}
@Test
@@ -125,21 +130,21 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
assertThat(metadata).has(Metadata.withProperty("simple.type.my-string", String.class));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-byte", Byte.class));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class).withDefaultValue(0));
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class).withDefaultValue(0));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-char", Character.class));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-char", Character.class));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-boolean", Boolean.class));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class).withDefaultValue(false));
.has(Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class).withDefaultValue(false));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-short", Short.class));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-primitive-short", Short.class).withDefaultValue(0));
.has(Metadata.withProperty("simple.type.my-primitive-short", Short.class).withDefaultValue(0));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-integer", Integer.class));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-primitive-integer", Integer.class).withDefaultValue(0));
.has(Metadata.withProperty("simple.type.my-primitive-integer", Integer.class).withDefaultValue(0));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-long", Long.class));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class).withDefaultValue(0));
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class).withDefaultValue(0));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-double", Double.class));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-double", Double.class));
assertThat(metadata).has(Metadata.withProperty("simple.type.my-float", Float.class));
@@ -152,12 +157,15 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(HierarchicalProperties.class, HierarchicalPropertiesParent.class,
HierarchicalPropertiesGrandparent.class);
assertThat(metadata).has(Metadata.withGroup("hierarchical").fromSource(HierarchicalProperties.class));
assertThat(metadata).has(Metadata.withProperty("hierarchical.first", String.class).withDefaultValue("one")
.fromSource(HierarchicalProperties.class));
assertThat(metadata).has(Metadata.withProperty("hierarchical.second", String.class).withDefaultValue("two")
.fromSource(HierarchicalProperties.class));
assertThat(metadata).has(Metadata.withProperty("hierarchical.third", String.class).withDefaultValue("three")
.fromSource(HierarchicalProperties.class));
assertThat(metadata).has(Metadata.withProperty("hierarchical.first", String.class)
.withDefaultValue("one")
.fromSource(HierarchicalProperties.class));
assertThat(metadata).has(Metadata.withProperty("hierarchical.second", String.class)
.withDefaultValue("two")
.fromSource(HierarchicalProperties.class));
assertThat(metadata).has(Metadata.withProperty("hierarchical.third", String.class)
.withDefaultValue("three")
.fromSource(HierarchicalProperties.class));
}
@Test
@@ -165,10 +173,12 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(DescriptionProperties.class);
assertThat(metadata).has(Metadata.withGroup("description").fromSource(DescriptionProperties.class));
assertThat(metadata).has(Metadata.withProperty("description.simple", String.class)
.fromSource(DescriptionProperties.class).withDescription("A simple description."));
.fromSource(DescriptionProperties.class)
.withDescription("A simple description."));
assertThat(metadata).has(Metadata.withProperty("description.multi-line", String.class)
.fromSource(DescriptionProperties.class).withDescription(
"This is a lengthy description that spans across multiple lines to showcase that the line separators are cleaned automatically."));
.fromSource(DescriptionProperties.class)
.withDescription(
"This is a lengthy description that spans across multiple lines to showcase that the line separators are cleaned automatically."));
}
@Test
@@ -177,10 +187,11 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
Class<?> type = org.springframework.boot.configurationsample.simple.DeprecatedProperties.class;
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("deprecated").fromSource(type));
assertThat(metadata).has(
Metadata.withProperty("deprecated.name", String.class).fromSource(type).withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("deprecated.description", String.class).fromSource(type)
.withDeprecation(null, null));
assertThat(metadata)
.has(Metadata.withProperty("deprecated.name", String.class).fromSource(type).withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("deprecated.description", String.class)
.fromSource(type)
.withDeprecation(null, null));
}
@Test
@@ -189,8 +200,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("singledeprecated").fromSource(type));
assertThat(metadata).has(Metadata.withProperty("singledeprecated.new-name", String.class).fromSource(type));
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class).fromSource(type)
.withDeprecation("renamed", "singledeprecated.new-name"));
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class)
.fromSource(type)
.withDeprecation("renamed", "singledeprecated.new-name"));
}
@Test
@@ -198,8 +210,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
Class<?> type = DeprecatedFieldSingleProperty.class;
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("singlefielddeprecated").fromSource(type));
assertThat(metadata).has(Metadata.withProperty("singlefielddeprecated.name", String.class).fromSource(type)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("singlefielddeprecated.name", String.class)
.fromSource(type)
.withDeprecation(null, null));
}
@Test
@@ -207,10 +220,12 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
Class<?> type = DeprecatedUnrelatedMethodPojo.class;
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("not.deprecated").fromSource(type));
assertThat(metadata).has(
Metadata.withProperty("not.deprecated.counter", Integer.class).withNoDeprecation().fromSource(type));
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class).withDefaultValue(false)
.withNoDeprecation().fromSource(type));
assertThat(metadata)
.has(Metadata.withProperty("not.deprecated.counter", Integer.class).withNoDeprecation().fromSource(type));
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class)
.withDefaultValue(false)
.withNoDeprecation()
.fromSource(type));
}
@Test
@@ -218,8 +233,10 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
Class<?> type = DeprecatedLessPreciseTypePojo.class;
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("not.deprecated").fromSource(type));
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class).withDefaultValue(false)
.withNoDeprecation().fromSource(type));
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class)
.withDefaultValue(false)
.withNoDeprecation()
.fromSource(type));
}
@Test
@@ -227,8 +244,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
Class<?> type = DeprecatedRecord.class;
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("deprecated-record").fromSource(type));
assertThat(metadata).has(Metadata.withProperty("deprecated-record.alpha", String.class).fromSource(type)
.withDeprecation("some-reason", null));
assertThat(metadata).has(Metadata.withProperty("deprecated-record.alpha", String.class)
.fromSource(type)
.withDeprecation("some-reason", null));
assertThat(metadata).has(Metadata.withProperty("deprecated-record.bravo", String.class).fromSource(type));
}
@@ -238,7 +256,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("boxing").fromSource(type));
assertThat(metadata)
.has(Metadata.withProperty("boxing.flag", Boolean.class).withDefaultValue(false).fromSource(type));
.has(Metadata.withProperty("boxing.flag", Boolean.class).withDefaultValue(false).fromSource(type));
assertThat(metadata).has(Metadata.withProperty("boxing.another-flag", Boolean.class).fromSource(type));
assertThat(metadata).has(Metadata.withProperty("boxing.counter", Integer.class).fromSource(type));
}
@@ -268,8 +286,8 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
assertThat(metadata).has(Metadata.withProperty("array.simple", "java.lang.String[]"));
assertThat(metadata).has(Metadata.withProperty("array.inner",
"org.springframework.boot.configurationsample.simple.SimpleArrayProperties$Holder[]"));
assertThat(metadata).has(
Metadata.withProperty("array.name-to-integer", "java.util.Map<java.lang.String,java.lang.Integer>[]"));
assertThat(metadata)
.has(Metadata.withProperty("array.name-to-integer", "java.util.Map<java.lang.String,java.lang.Integer>[]"));
assertThat(metadata.getItems()).hasSize(5);
}
@@ -278,7 +296,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(AnnotatedGetter.class);
assertThat(metadata).has(Metadata.withGroup("specific").fromSource(AnnotatedGetter.class));
assertThat(metadata)
.has(Metadata.withProperty("specific.name", String.class).fromSource(AnnotatedGetter.class));
.has(Metadata.withProperty("specific.name", String.class).fromSource(AnnotatedGetter.class));
}
@Test
@@ -286,9 +304,10 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(StaticAccessor.class);
assertThat(metadata).has(Metadata.withGroup("specific").fromSource(StaticAccessor.class));
assertThat(metadata).has(Metadata.withProperty("specific.counter", Integer.class)
.fromSource(StaticAccessor.class).withDefaultValue(42));
.fromSource(StaticAccessor.class)
.withDefaultValue(42));
assertThat(metadata)
.doesNotHave(Metadata.withProperty("specific.name", String.class).fromSource(StaticAccessor.class));
.doesNotHave(Metadata.withProperty("specific.name", String.class).fromSource(StaticAccessor.class));
assertThat(metadata.getItems()).hasSize(2);
}
@@ -302,16 +321,17 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
void innerClassProperties() {
ConfigurationMetadata metadata = compile(InnerClassProperties.class);
assertThat(metadata).has(Metadata.withGroup("config").fromSource(InnerClassProperties.class));
assertThat(metadata).has(Metadata.withGroup("config.first").ofType(InnerClassProperties.Foo.class)
.fromSource(InnerClassProperties.class));
assertThat(metadata).has(Metadata.withGroup("config.first")
.ofType(InnerClassProperties.Foo.class)
.fromSource(InnerClassProperties.class));
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
assertThat(metadata).has(Metadata.withProperty("config.first.bar.name"));
assertThat(metadata).has(Metadata.withGroup("config.the-second", InnerClassProperties.Foo.class)
.fromSource(InnerClassProperties.class));
.fromSource(InnerClassProperties.class));
assertThat(metadata).has(Metadata.withProperty("config.the-second.name"));
assertThat(metadata).has(Metadata.withProperty("config.the-second.bar.name"));
assertThat(metadata).has(
Metadata.withGroup("config.third").ofType(SimplePojo.class).fromSource(InnerClassProperties.class));
assertThat(metadata)
.has(Metadata.withGroup("config.third").ofType(SimplePojo.class).fromSource(InnerClassProperties.class));
assertThat(metadata).has(Metadata.withProperty("config.third.value"));
assertThat(metadata).has(Metadata.withProperty("config.fourth"));
assertThat(metadata).isNotEqualTo(Metadata.withGroup("config.fourth"));
@@ -322,9 +342,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
ConfigurationMetadata metadata = compile(InnerClassHierarchicalProperties.class);
assertThat(metadata).has(Metadata.withGroup("config.foo").ofType(InnerClassHierarchicalProperties.Foo.class));
assertThat(metadata)
.has(Metadata.withGroup("config.foo.bar").ofType(InnerClassHierarchicalProperties.Bar.class));
.has(Metadata.withGroup("config.foo.bar").ofType(InnerClassHierarchicalProperties.Bar.class));
assertThat(metadata)
.has(Metadata.withGroup("config.foo.bar.baz").ofType(InnerClassHierarchicalProperties.Foo.Baz.class));
.has(Metadata.withGroup("config.foo.bar.baz").ofType(InnerClassHierarchicalProperties.Foo.Baz.class));
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.baz.blah"));
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.bling"));
}
@@ -340,12 +360,14 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
@Test
void nestedClassChildProperties() {
ConfigurationMetadata metadata = compile(ClassWithNestedProperties.class);
assertThat(metadata).has(
Metadata.withGroup("nestedChildProps").fromSource(ClassWithNestedProperties.NestedChildClass.class));
assertThat(metadata)
.has(Metadata.withGroup("nestedChildProps").fromSource(ClassWithNestedProperties.NestedChildClass.class));
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.child-class-property", Integer.class)
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(20));
.fromSource(ClassWithNestedProperties.NestedChildClass.class)
.withDefaultValue(20));
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.parent-class-property", Integer.class)
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(10));
.fromSource(ClassWithNestedProperties.NestedChildClass.class)
.withDefaultValue(10));
}
@Test
@@ -385,37 +407,40 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
@Test
void invalidDoubleRegistration() {
assertThatExceptionOfType(CompilationException.class)
.isThrownBy(() -> compile(InvalidDoubleRegistrationProperties.class))
.withMessageContaining("Unable to compile source");
.isThrownBy(() -> compile(InvalidDoubleRegistrationProperties.class))
.withMessageContaining("Unable to compile source");
}
@Test
void constructorParameterPropertyWithInvalidDefaultValueOnNumber() {
assertThatExceptionOfType(CompilationException.class)
.isThrownBy(() -> compile(InvalidDefaultValueNumberProperties.class))
.withMessageContaining("Unable to compile source");
.isThrownBy(() -> compile(InvalidDefaultValueNumberProperties.class))
.withMessageContaining("Unable to compile source");
}
@Test
void constructorParameterPropertyWithInvalidDefaultValueOnFloatingPoint() {
assertThatExceptionOfType(CompilationException.class)
.isThrownBy(() -> compile(InvalidDefaultValueFloatingPointProperties.class))
.withMessageContaining("Unable to compile source");
.isThrownBy(() -> compile(InvalidDefaultValueFloatingPointProperties.class))
.withMessageContaining("Unable to compile source");
}
@Test
void constructorParameterPropertyWithInvalidDefaultValueOnCharacter() {
assertThatExceptionOfType(CompilationException.class)
.isThrownBy(() -> compile(InvalidDefaultValueCharacterProperties.class))
.withMessageContaining("Unable to compile source");
.isThrownBy(() -> compile(InvalidDefaultValueCharacterProperties.class))
.withMessageContaining("Unable to compile source");
}
@Test
void constructorParameterPropertyWithEmptyDefaultValueOnProperty() {
ConfigurationMetadata metadata = compile(EmptyDefaultValueProperties.class);
assertThat(metadata).has(Metadata.withProperty("test.name"));
ItemMetadata nameMetadata = metadata.getItems().stream().filter((item) -> item.getName().equals("test.name"))
.findFirst().get();
ItemMetadata nameMetadata = metadata.getItems()
.stream()
.filter((item) -> item.getName().equals("test.name"))
.findFirst()
.get();
assertThat(nameMetadata.getDefaultValue()).isNull();
}
@@ -447,9 +472,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
""";
ConfigurationMetadata metadata = compile(source);
assertThat(metadata)
.has(Metadata.withProperty("record.defaults.some-string", String.class).withDefaultValue("An1s9n"));
.has(Metadata.withProperty("record.defaults.some-string", String.class).withDefaultValue("An1s9n"));
assertThat(metadata)
.has(Metadata.withProperty("record.defaults.some-integer", Integer.class).withDefaultValue(594));
.has(Metadata.withProperty("record.defaults.some-integer", Integer.class).withDefaultValue(594));
}
@Test

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.
@@ -99,8 +99,12 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
process(ImmutableSimpleProperties.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "counter");
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.counter").hasType(Long.class)
.hasSourceType(ImmutableSimpleProperties.class).hasNoDescription().isNotDeprecated();
assertItemMetadata(metadataEnv, property).isProperty()
.hasName("test.counter")
.hasType(Long.class)
.hasSourceType(ImmutableSimpleProperties.class)
.hasNoDescription()
.isNotDeprecated();
});
}
@@ -109,10 +113,13 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
process(ImmutableInnerClassProperties.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(ImmutableInnerClassProperties.class);
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
.hasType("org.springframework.boot.configurationsample.immutable.ImmutableInnerClassProperties$Foo")
.hasSourceType(ImmutableInnerClassProperties.class).hasSourceMethod("getFirst()").hasNoDescription()
.isNotDeprecated();
assertItemMetadata(metadataEnv, property).isGroup()
.hasName("test.first")
.hasType("org.springframework.boot.configurationsample.immutable.ImmutableInnerClassProperties$Foo")
.hasSourceType(ImmutableInnerClassProperties.class)
.hasSourceMethod("getFirst()")
.hasNoDescription()
.isNotDeprecated();
});
}
@@ -135,7 +142,7 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
assertItemMetadata(metadataEnv, property).isProperty()
.hasDescription("The name of this simple properties.");
.hasDescription("The name of this simple properties.");
});
}
@@ -156,7 +163,7 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet")).hasDefaultValue((byte) 0);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue(null);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number"))
.hasDefaultValue((short) 0);
.hasDefaultValue((short) 0);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(0);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(0L);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0F);
@@ -170,10 +177,10 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
TypeElement ownerElement = roundEnv.getRootElement(ImmutablePrimitiveWithDefaultsProperties.class);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flag")).hasDefaultValue(true);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet"))
.hasDefaultValue((byte) 120);
.hasDefaultValue((byte) 120);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue("a");
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number"))
.hasDefaultValue((short) 1000);
.hasDefaultValue((short) 1000);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(42);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(2000L);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0.5F);
@@ -187,10 +194,10 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
TypeElement ownerElement = roundEnv.getRootElement(ImmutablePrimitiveWrapperWithDefaultsProperties.class);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flag")).hasDefaultValue(true);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet"))
.hasDefaultValue((byte) 120);
.hasDefaultValue((byte) 120);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue("a");
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number"))
.hasDefaultValue((short) 1000);
.hasDefaultValue((short) 1000);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(42);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(2000L);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0.5F);
@@ -204,9 +211,9 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
TypeElement ownerElement = roundEnv.getRootElement(ImmutableCollectionProperties.class);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "names")).hasDefaultValue(null);
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flags"))
.hasDefaultValue(Arrays.asList(true, false));
.hasDefaultValue(Arrays.asList(true, false));
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "durations"))
.hasDefaultValue(Arrays.asList("10s", "1m", "1h"));
.hasDefaultValue(Arrays.asList("10s", "1m", "1h"));
});
}
@@ -220,13 +227,19 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
}
private VariableElement getConstructorParameter(TypeElement ownerElement, String name) {
List<ExecutableElement> constructors = ElementFilter.constructorsIn(ownerElement.getEnclosedElements()).stream()
.filter((constructor) -> !constructor.getParameters().isEmpty()).toList();
List<ExecutableElement> constructors = ElementFilter.constructorsIn(ownerElement.getEnclosedElements())
.stream()
.filter((constructor) -> !constructor.getParameters().isEmpty())
.toList();
if (constructors.size() != 1) {
throw new IllegalStateException("No candidate constructor for " + ownerElement);
}
return constructors.get(0).getParameters().stream()
.filter((parameter) -> parameter.getSimpleName().toString().equals(name)).findFirst().orElse(null);
return constructors.get(0)
.getParameters()
.stream()
.filter((parameter) -> parameter.getSimpleName().toString().equals(name))
.findFirst()
.orElse(null);
}
}

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.
@@ -38,11 +38,14 @@ class DeducedImmutablePropertiesMetadataGenerationTests extends AbstractMetadata
ConfigurationMetadata metadata = compile(DeducedImmutableClassProperties.class);
assertThat(metadata).has(Metadata.withGroup("test").fromSource(DeducedImmutableClassProperties.class));
assertThat(metadata).has(Metadata.withGroup("test.nested", DeducedImmutableClassProperties.Nested.class)
.fromSource(DeducedImmutableClassProperties.class));
.fromSource(DeducedImmutableClassProperties.class));
assertThat(metadata).has(Metadata.withProperty("test.nested.name", String.class)
.fromSource(DeducedImmutableClassProperties.Nested.class));
ItemMetadata nestedMetadata = metadata.getItems().stream()
.filter((item) -> item.getName().equals("test.nested")).findFirst().get();
.fromSource(DeducedImmutableClassProperties.Nested.class));
ItemMetadata nestedMetadata = metadata.getItems()
.stream()
.filter((item) -> item.getName().equals("test.nested"))
.findFirst()
.get();
assertThat(nestedMetadata.getDefaultValue()).isNull();
}

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.
@@ -69,9 +69,10 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
void customPropertiesEndpoint() {
ConfigurationMetadata metadata = compile(CustomPropertiesEndpoint.class);
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.customprops").fromSource(CustomPropertiesEndpoint.class));
assertThat(metadata).has(Metadata.withProperty("management.endpoint.customprops.name").ofType(String.class)
.withDefaultValue("test"));
.has(Metadata.withGroup("management.endpoint.customprops").fromSource(CustomPropertiesEndpoint.class));
assertThat(metadata).has(Metadata.withProperty("management.endpoint.customprops.name")
.ofType(String.class)
.withDefaultValue("test"));
assertThat(metadata).has(enabledFlag("customprops", true));
assertThat(metadata).has(cacheTtl("customprops"));
assertThat(metadata.getItems()).hasSize(4);
@@ -90,7 +91,7 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
void camelCaseEndpoint() {
ConfigurationMetadata metadata = compile(CamelCaseEndpoint.class);
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.pascal-case").fromSource(CamelCaseEndpoint.class));
.has(Metadata.withGroup("management.endpoint.pascal-case").fromSource(CamelCaseEndpoint.class));
assertThat(metadata).has(enabledFlag("PascalCase", "pascal-case", true));
assertThat(metadata.getItems()).hasSize(2);
}
@@ -100,7 +101,7 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
TestProject project = new TestProject(IncrementalEndpoint.class);
ConfigurationMetadata metadata = project.compile();
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
assertThat(metadata).has(enabledFlag("incremental", true));
assertThat(metadata).has(cacheTtl("incremental"));
assertThat(metadata.getItems()).hasSize(3);
@@ -108,7 +109,7 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
"id = \"incremental\", enableByDefault = false");
metadata = project.compile();
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
assertThat(metadata).has(enabledFlag("incremental", false));
assertThat(metadata).has(cacheTtl("incremental"));
assertThat(metadata.getItems()).hasSize(3);
@@ -119,14 +120,14 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
TestProject project = new TestProject(IncrementalEndpoint.class);
ConfigurationMetadata metadata = project.compile();
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
assertThat(metadata).has(enabledFlag("incremental", true));
assertThat(metadata).has(cacheTtl("incremental"));
assertThat(metadata.getItems()).hasSize(3);
project.replaceText(IncrementalEndpoint.class, "@Nullable String param", "String param");
metadata = project.compile();
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
assertThat(metadata).has(enabledFlag("incremental", true));
assertThat(metadata.getItems()).hasSize(2);
}
@@ -149,8 +150,8 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
private Metadata.MetadataItemCondition enabledFlag(String endpointId, String endpointSuffix, Boolean defaultValue) {
return Metadata.withEnabledFlag("management.endpoint." + endpointSuffix + ".enabled")
.withDefaultValue(defaultValue)
.withDescription(String.format("Whether to enable the %s endpoint.", endpointId));
.withDefaultValue(defaultValue)
.withDescription(String.format("Whether to enable the %s endpoint.", endpointId));
}
private Metadata.MetadataItemCondition enabledFlag(String endpointId, Boolean defaultValue) {
@@ -158,8 +159,10 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
}
private Metadata.MetadataItemCondition cacheTtl(String endpointId) {
return Metadata.withProperty("management.endpoint." + endpointId + ".cache.time-to-live").ofType(Duration.class)
.withDefaultValue("0ms").withDescription("Maximum time that a response can be cached.");
return Metadata.withProperty("management.endpoint." + endpointId + ".cache.time-to-live")
.ofType(Duration.class)
.withDefaultValue("0ms")
.withDescription("Maximum time that a response can be cached.");
}
}

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.
@@ -43,10 +43,14 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
ConfigurationMetadata metadata = compile(AbstractGenericProperties.class, SimpleGenericProperties.class);
assertThat(metadata).has(Metadata.withGroup("generic").fromSource(SimpleGenericProperties.class));
assertThat(metadata).has(Metadata.withProperty("generic.name", String.class)
.fromSource(SimpleGenericProperties.class).withDescription("Generic name.").withDefaultValue(null));
assertThat(metadata).has(Metadata
.withProperty("generic.mappings", "java.util.Map<java.lang.Integer,java.time.Duration>")
.fromSource(SimpleGenericProperties.class).withDescription("Generic mappings.").withDefaultValue(null));
.fromSource(SimpleGenericProperties.class)
.withDescription("Generic name.")
.withDefaultValue(null));
assertThat(metadata)
.has(Metadata.withProperty("generic.mappings", "java.util.Map<java.lang.Integer,java.time.Duration>")
.fromSource(SimpleGenericProperties.class)
.withDescription("Generic mappings.")
.withDefaultValue(null));
assertThat(metadata.getItems()).hasSize(3);
}
@@ -54,11 +58,12 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
void complexGenericProperties() {
ConfigurationMetadata metadata = compile(ComplexGenericProperties.class);
assertThat(metadata).has(Metadata.withGroup("generic").fromSource(ComplexGenericProperties.class));
assertThat(metadata).has(Metadata.withGroup("generic.test").ofType(UpperBoundGenericPojo.class)
.fromSource(ComplexGenericProperties.class));
assertThat(metadata).has(Metadata.withGroup("generic.test")
.ofType(UpperBoundGenericPojo.class)
.fromSource(ComplexGenericProperties.class));
assertThat(metadata)
.has(Metadata.withProperty("generic.test.mappings", "java.util.Map<java.lang.Enum<T>,java.lang.String>")
.fromSource(UpperBoundGenericPojo.class));
.has(Metadata.withProperty("generic.test.mappings", "java.util.Map<java.lang.Enum<T>,java.lang.String>")
.fromSource(UpperBoundGenericPojo.class));
assertThat(metadata.getItems()).hasSize(3);
}
@@ -67,11 +72,14 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
ConfigurationMetadata metadata = compile(AbstractGenericProperties.class, UnresolvedGenericProperties.class);
assertThat(metadata).has(Metadata.withGroup("generic").fromSource(UnresolvedGenericProperties.class));
assertThat(metadata).has(Metadata.withProperty("generic.name", String.class)
.fromSource(UnresolvedGenericProperties.class).withDescription("Generic name.").withDefaultValue(null));
.fromSource(UnresolvedGenericProperties.class)
.withDescription("Generic name.")
.withDefaultValue(null));
assertThat(metadata)
.has(Metadata.withProperty("generic.mappings", "java.util.Map<java.lang.Number,java.lang.Object>")
.fromSource(UnresolvedGenericProperties.class).withDescription("Generic mappings.")
.withDefaultValue(null));
.has(Metadata.withProperty("generic.mappings", "java.util.Map<java.lang.Number,java.lang.Object>")
.fromSource(UnresolvedGenericProperties.class)
.withDescription("Generic mappings.")
.withDefaultValue(null));
assertThat(metadata.getItems()).hasSize(3);
}
@@ -79,24 +87,27 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
void genericTypes() {
ConfigurationMetadata metadata = compile(GenericConfig.class);
assertThat(metadata).has(Metadata.withGroup("generic")
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig"));
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig"));
assertThat(metadata).has(Metadata.withGroup("generic.foo")
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Foo"));
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Foo"));
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar")
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Bar"));
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Bar"));
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar.biz")
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Bar$Biz"));
assertThat(metadata).has(
Metadata.withProperty("generic.foo.name").ofType(String.class).fromSource(GenericConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-bar").ofType(
"java.util.Map<java.lang.String,org.springframework.boot.configurationsample.generic.GenericConfig$Bar<java.lang.Integer>>")
.fromSource(GenericConfig.Foo.class));
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Bar$Biz"));
assertThat(metadata)
.has(Metadata.withProperty("generic.foo.name").ofType(String.class).fromSource(GenericConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-bar")
.ofType("java.util.Map<java.lang.String,org.springframework.boot.configurationsample.generic.GenericConfig$Bar<java.lang.Integer>>")
.fromSource(GenericConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-integer")
.ofType("java.util.Map<java.lang.String,java.lang.Integer>").fromSource(GenericConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.name").ofType("java.lang.String")
.fromSource(GenericConfig.Bar.class));
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.biz.name").ofType("java.lang.String")
.fromSource(GenericConfig.Bar.Biz.class));
.ofType("java.util.Map<java.lang.String,java.lang.Integer>")
.fromSource(GenericConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.name")
.ofType("java.lang.String")
.fromSource(GenericConfig.Bar.class));
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.biz.name")
.ofType("java.lang.String")
.fromSource(GenericConfig.Bar.Biz.class));
assertThat(metadata.getItems()).hasSize(9);
}
@@ -105,9 +116,11 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
ConfigurationMetadata metadata = compile(WildcardConfig.class);
assertThat(metadata).has(Metadata.withGroup("wildcard").ofType(WildcardConfig.class));
assertThat(metadata).has(Metadata.withProperty("wildcard.string-to-number")
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>").fromSource(WildcardConfig.class));
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>")
.fromSource(WildcardConfig.class));
assertThat(metadata).has(Metadata.withProperty("wildcard.integers")
.ofType("java.util.List<? super java.lang.Integer>").fromSource(WildcardConfig.class));
.ofType("java.util.List<? super java.lang.Integer>")
.fromSource(WildcardConfig.class));
assertThat(metadata.getItems()).hasSize(3);
}
@@ -115,8 +128,8 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
void builderPatternWithGenericReturnType() {
ConfigurationMetadata metadata = compile(ConcreteBuilderProperties.class);
assertThat(metadata).has(Metadata.withGroup("builder").fromSource(ConcreteBuilderProperties.class));
assertThat(metadata).has(
Metadata.withProperty("builder.number", Integer.class).fromSource(ConcreteBuilderProperties.class));
assertThat(metadata)
.has(Metadata.withProperty("builder.number", Integer.class).fromSource(ConcreteBuilderProperties.class));
assertThat(metadata).has(
Metadata.withProperty("builder.description", String.class).fromSource(ConcreteBuilderProperties.class));
assertThat(metadata.getItems()).hasSize(3);

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.
@@ -35,7 +35,7 @@ class ImmutableNameAnnotationPropertiesTests extends AbstractMetadataGenerationT
void immutableNameAnnotationProperties() {
ConfigurationMetadata metadata = compile(ImmutableNameAnnotationProperties.class);
assertThat(metadata).has(Metadata.withProperty("named.import", String.class)
.fromSource(ImmutableNameAnnotationProperties.class));
.fromSource(ImmutableNameAnnotationProperties.class));
}
}

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.
@@ -35,12 +35,15 @@ class ImmutablePropertiesMetadataGenerationTests extends AbstractMetadataGenerat
void immutableSimpleProperties() {
ConfigurationMetadata metadata = compile(ImmutableSimpleProperties.class);
assertThat(metadata).has(Metadata.withGroup("immutable").fromSource(ImmutableSimpleProperties.class));
assertThat(metadata).has(
Metadata.withProperty("immutable.the-name", String.class).fromSource(ImmutableSimpleProperties.class)
.withDescription("The name of this simple properties.").withDefaultValue("boot"));
assertThat(metadata).has(Metadata.withProperty("immutable.flag", Boolean.class).withDefaultValue(false)
.fromSource(ImmutableSimpleProperties.class).withDescription("A simple flag.")
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("immutable.the-name", String.class)
.fromSource(ImmutableSimpleProperties.class)
.withDescription("The name of this simple properties.")
.withDefaultValue("boot"));
assertThat(metadata).has(Metadata.withProperty("immutable.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(ImmutableSimpleProperties.class)
.withDescription("A simple flag.")
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("immutable.comparator"));
assertThat(metadata).has(Metadata.withProperty("immutable.counter"));
assertThat(metadata.getItems()).hasSize(5);

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.
@@ -41,14 +41,14 @@ class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGeneration
TestProject project = new TestProject(FooProperties.class, BarProperties.class);
ConfigurationMetadata metadata = project.compile();
assertThat(metadata)
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
assertThat(metadata)
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
metadata = project.compile();
assertThat(metadata)
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
assertThat(metadata)
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
project.addSourceCode(BarProperties.class, BarProperties.class.getResourceAsStream("BarProperties.snippet"));
metadata = project.compile();
assertThat(metadata).has(Metadata.withProperty("bar.extra"));
@@ -79,19 +79,19 @@ class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGeneration
TestProject project = new TestProject(FooProperties.class, BarProperties.class);
ConfigurationMetadata metadata = project.compile();
assertThat(metadata)
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
assertThat(metadata)
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter").fromSource(RenamedBarProperties.class));
project.delete(BarProperties.class);
project.add(RenamedBarProperties.class);
metadata = project.compile();
assertThat(metadata)
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
assertThat(metadata)
.doesNotHave(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
.doesNotHave(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
assertThat(metadata)
.has(Metadata.withProperty("bar.counter").withDefaultValue(0).fromSource(RenamedBarProperties.class));
.has(Metadata.withProperty("bar.counter").withDefaultValue(0).fromSource(RenamedBarProperties.class));
}
@Test

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.
@@ -128,8 +128,12 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
process(SimpleTypeProperties.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(SimpleTypeProperties.class);
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "myString");
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.my-string").hasType(String.class)
.hasSourceType(SimpleTypeProperties.class).hasNoDescription().isNotDeprecated();
assertItemMetadata(metadataEnv, property).isProperty()
.hasName("test.my-string")
.hasType(String.class)
.hasSourceType(SimpleTypeProperties.class)
.hasNoDescription()
.isNotDeprecated();
});
}
@@ -138,9 +142,12 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
process(SimpleCollectionProperties.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(SimpleCollectionProperties.class);
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "doubles");
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.doubles")
.hasType("java.util.List<java.lang.Double>").hasSourceType(SimpleCollectionProperties.class)
.hasNoDescription().isNotDeprecated();
assertItemMetadata(metadataEnv, property).isProperty()
.hasName("test.doubles")
.hasType("java.util.List<java.lang.Double>")
.hasSourceType(SimpleCollectionProperties.class)
.hasNoDescription()
.isNotDeprecated();
});
}
@@ -149,10 +156,13 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
process(InnerClassProperties.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(InnerClassProperties.class);
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
.hasType("org.springframework.boot.configurationsample.specific.InnerClassProperties$Foo")
.hasSourceType(InnerClassProperties.class).hasSourceMethod("getFirst()").hasNoDescription()
.isNotDeprecated();
assertItemMetadata(metadataEnv, property).isGroup()
.hasName("test.first")
.hasType("org.springframework.boot.configurationsample.specific.InnerClassProperties$Foo")
.hasSourceType(InnerClassProperties.class)
.hasSourceMethod("getFirst()")
.hasNoDescription()
.isNotDeprecated();
});
}
@@ -172,8 +182,8 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
void javaBeanDeprecatedPropertyOnClass() {
process(org.springframework.boot.configurationsample.simple.DeprecatedProperties.class,
(roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(
org.springframework.boot.configurationsample.simple.DeprecatedProperties.class);
TypeElement ownerElement = roundEnv
.getRootElement(org.springframework.boot.configurationsample.simple.DeprecatedProperties.class);
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithNoInformation();
});
@@ -184,8 +194,9 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
process(DeprecatedSingleProperty.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(DeprecatedSingleProperty.class);
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithReason("renamed")
.isDeprecatedWithReplacement("singledeprecated.new-name");
assertItemMetadata(metadataEnv, property).isProperty()
.isDeprecatedWithReason("renamed")
.isDeprecatedWithReplacement("singledeprecated.new-name");
});
}
@@ -213,7 +224,7 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
assertItemMetadata(metadataEnv, property).isProperty()
.hasDescription("The name of this simple properties.");
.hasDescription("The name of this simple properties.");
});
}

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.
@@ -97,16 +97,18 @@ class LombokMetadataGenerationTests extends AbstractMetadataGenerationTests {
void lombokInnerClassProperties() {
ConfigurationMetadata metadata = compile(LombokInnerClassProperties.class);
assertThat(metadata).has(Metadata.withGroup("config").fromSource(LombokInnerClassProperties.class));
assertThat(metadata).has(Metadata.withGroup("config.first").ofType(LombokInnerClassProperties.Foo.class)
.fromSource(LombokInnerClassProperties.class));
assertThat(metadata).has(Metadata.withGroup("config.first")
.ofType(LombokInnerClassProperties.Foo.class)
.fromSource(LombokInnerClassProperties.class));
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
assertThat(metadata).has(Metadata.withProperty("config.first.bar.name"));
assertThat(metadata).has(Metadata.withGroup("config.second", LombokInnerClassProperties.Foo.class)
.fromSource(LombokInnerClassProperties.class));
.fromSource(LombokInnerClassProperties.class));
assertThat(metadata).has(Metadata.withProperty("config.second.name"));
assertThat(metadata).has(Metadata.withProperty("config.second.bar.name"));
assertThat(metadata).has(Metadata.withGroup("config.third").ofType(SimpleLombokPojo.class)
.fromSource(LombokInnerClassProperties.class));
assertThat(metadata).has(Metadata.withGroup("config.third")
.ofType(SimpleLombokPojo.class)
.fromSource(LombokInnerClassProperties.class));
// For some reason the annotation processor resolves a type for SimpleLombokPojo
// that is resolved (compiled) and the source annotations are gone. Because we
// don't see the @Data annotation anymore, no field is harvested. What is crazy is
@@ -121,9 +123,10 @@ class LombokMetadataGenerationTests extends AbstractMetadataGenerationTests {
void lombokInnerClassWithGetterProperties() {
ConfigurationMetadata metadata = compile(LombokInnerClassWithGetterProperties.class);
assertThat(metadata).has(Metadata.withGroup("config").fromSource(LombokInnerClassWithGetterProperties.class));
assertThat(metadata)
.has(Metadata.withGroup("config.first").ofType(LombokInnerClassWithGetterProperties.Foo.class)
.fromSourceMethod("getFirst()").fromSource(LombokInnerClassWithGetterProperties.class));
assertThat(metadata).has(Metadata.withGroup("config.first")
.ofType(LombokInnerClassWithGetterProperties.Foo.class)
.fromSourceMethod("getFirst()")
.fromSource(LombokInnerClassWithGetterProperties.class));
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
assertThat(metadata.getItems()).hasSize(3);
}
@@ -131,12 +134,15 @@ class LombokMetadataGenerationTests extends AbstractMetadataGenerationTests {
private void assertSimpleLombokProperties(ConfigurationMetadata metadata, Class<?> source, String prefix) {
assertThat(metadata).has(Metadata.withGroup(prefix).fromSource(source));
assertThat(metadata).doesNotHave(Metadata.withProperty(prefix + ".id"));
assertThat(metadata).has(Metadata.withProperty(prefix + ".name", String.class).fromSource(source)
.withDescription("Name description."));
assertThat(metadata).has(Metadata.withProperty(prefix + ".name", String.class)
.fromSource(source)
.withDescription("Name description."));
assertThat(metadata).has(Metadata.withProperty(prefix + ".description"));
assertThat(metadata).has(Metadata.withProperty(prefix + ".counter"));
assertThat(metadata).has(Metadata.withProperty(prefix + ".number").fromSource(source).withDefaultValue(0)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty(prefix + ".number")
.fromSource(source)
.withDefaultValue(0)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty(prefix + ".items"));
assertThat(metadata).doesNotHave(Metadata.withProperty(prefix + ".ignored"));
}

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.
@@ -148,8 +148,12 @@ class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "description");
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.description").hasType(String.class)
.hasSourceType(LombokSimpleProperties.class).hasNoDescription().isNotDeprecated();
assertItemMetadata(metadataEnv, property).isProperty()
.hasName("test.description")
.hasType(String.class)
.hasSourceType(LombokSimpleProperties.class)
.hasNoDescription()
.isNotDeprecated();
});
}
@@ -158,9 +162,12 @@ class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "items");
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.items")
.hasType("java.util.List<java.lang.String>").hasSourceType(LombokSimpleProperties.class)
.hasNoDescription().isNotDeprecated();
assertItemMetadata(metadataEnv, property).isProperty()
.hasName("test.items")
.hasType("java.util.List<java.lang.String>")
.hasSourceType(LombokSimpleProperties.class)
.hasNoDescription()
.isNotDeprecated();
});
}
@@ -172,10 +179,13 @@ class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
ExecutableElement getter = getMethod(ownerElement, "getThird");
LombokPropertyDescriptor property = new LombokPropertyDescriptor(ownerElement, null, field, "third",
field.asType(), getter, null);
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.third")
.hasType("org.springframework.boot.configurationsample.lombok.SimpleLombokPojo")
.hasSourceType(LombokInnerClassProperties.class).hasSourceMethod("getThird()").hasNoDescription()
.isNotDeprecated();
assertItemMetadata(metadataEnv, property).isGroup()
.hasName("test.third")
.hasType("org.springframework.boot.configurationsample.lombok.SimpleLombokPojo")
.hasSourceType(LombokInnerClassProperties.class)
.hasSourceMethod("getThird()")
.hasNoDescription()
.isNotDeprecated();
});
}
@@ -184,10 +194,13 @@ class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
process(LombokInnerClassProperties.class, (roundEnv, metadataEnv) -> {
TypeElement ownerElement = roundEnv.getRootElement(LombokInnerClassProperties.class);
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
.hasType("org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties$Foo")
.hasSourceType(LombokInnerClassProperties.class).hasSourceMethod(null).hasNoDescription()
.isNotDeprecated();
assertItemMetadata(metadataEnv, property).isGroup()
.hasName("test.first")
.hasType("org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties$Foo")
.hasSourceType(LombokInnerClassProperties.class)
.hasSourceMethod(null)
.hasNoDescription()
.isNotDeprecated();
});
}

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.
@@ -71,8 +71,11 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null, null, null, true, null);
String additionalMetadata = buildAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class)
.withDescription("A simple flag.").withDeprecation(null, null).withDefaultValue(true));
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
.fromSource(SimpleProperties.class)
.withDescription("A simple flag.")
.withDeprecation(null, null)
.withDefaultValue(true));
assertThat(metadata.getItems()).hasSize(4);
}
@@ -84,17 +87,23 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class,
SimpleConflictingProperties.class);
assertThat(metadata.getItems()).hasSize(6);
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.getName().equals("simple.flag"))
.toList();
List<ItemMetadata> items = metadata.getItems()
.stream()
.filter((item) -> item.getName().equals("simple.flag"))
.toList();
assertThat(items).hasSize(2);
ItemMetadata matchingProperty = items.stream().filter((item) -> item.getType().equals(Boolean.class.getName()))
.findFirst().orElse(null);
ItemMetadata matchingProperty = items.stream()
.filter((item) -> item.getType().equals(Boolean.class.getName()))
.findFirst()
.orElse(null);
assertThat(matchingProperty).isNotNull();
assertThat(matchingProperty.getDefaultValue()).isEqualTo(true);
assertThat(matchingProperty.getSourceType()).isEqualTo(SimpleProperties.class.getName());
assertThat(matchingProperty.getDescription()).isEqualTo("A simple flag.");
ItemMetadata nonMatchingProperty = items.stream()
.filter((item) -> item.getType().equals(String.class.getName())).findFirst().orElse(null);
.filter((item) -> item.getType().equals(String.class.getName()))
.findFirst()
.orElse(null);
assertThat(nonMatchingProperty).isNotNull();
assertThat(nonMatchingProperty.getDefaultValue()).isEqualTo("hello");
assertThat(nonMatchingProperty.getSourceType()).isEqualTo(SimpleConflictingProperties.class.getName());
@@ -108,7 +117,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
String additionalMetadata = buildAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
.fromSource(SimpleProperties.class).withDescription("A nice comparator."));
.fromSource(SimpleProperties.class)
.withDescription("A nice comparator."));
assertThat(metadata.getItems()).hasSize(4);
}
@@ -118,9 +128,9 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
new ItemDeprecation("Don't use this.", "simple.complex-comparator", "error"));
String additionalMetadata = buildAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
assertThat(metadata).has(
Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class)
.withDeprecation("Don't use this.", "simple.complex-comparator", "error"));
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
.fromSource(SimpleProperties.class)
.withDeprecation("Don't use this.", "simple.complex-comparator", "error"));
assertThat(metadata.getItems()).hasSize(4);
}
@@ -131,7 +141,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
String additionalMetadata = buildAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(additionalMetadata, DeprecatedSingleProperty.class);
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
.fromSource(DeprecatedSingleProperty.class).withDeprecation("Don't use this.", "single.name"));
.fromSource(DeprecatedSingleProperty.class)
.withDeprecation("Don't use this.", "single.name"));
assertThat(metadata.getItems()).hasSize(3);
}
@@ -142,8 +153,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
String additionalMetadata = buildAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(additionalMetadata, DeprecatedSingleProperty.class);
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
.fromSource(DeprecatedSingleProperty.class)
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
.fromSource(DeprecatedSingleProperty.class)
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
assertThat(metadata.getItems()).hasSize(3);
}
@@ -151,8 +162,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
void mergeOfInvalidAdditionalMetadata() {
String metadata = "Hello World";
assertThatExceptionOfType(CompilationException.class)
.isThrownBy(() -> compile(metadata, SimpleProperties.class))
.withMessageContaining("Invalid additional meta-data");
.isThrownBy(() -> compile(metadata, SimpleProperties.class))
.withMessageContaining("Invalid additional meta-data");
}
@Test
@@ -161,10 +172,12 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
new ItemHint.ValueHint("boot", "Bla bla"), new ItemHint.ValueHint("spring", null)));
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
.withDefaultValue("boot").withDeprecation(null, null));
.fromSource(SimpleProperties.class)
.withDescription("The name of this simple properties.")
.withDefaultValue("boot")
.withDeprecation(null, null));
assertThat(metadata)
.has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla").withValue(1, "spring", null));
.has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla").withValue(1, "spring", null));
}
@Test
@@ -173,8 +186,10 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
ItemHint.newHint("simple.theName", new ItemHint.ValueHint("boot", "Bla bla")));
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
.withDefaultValue("boot").withDeprecation(null, null));
.fromSource(SimpleProperties.class)
.withDescription("The name of this simple properties.")
.withDefaultValue("boot")
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla"));
}
@@ -185,8 +200,10 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
new ItemHint.ValueProvider("second", null))));
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
.withDefaultValue("boot").withDeprecation(null, null));
.fromSource(SimpleProperties.class)
.withDescription("The name of this simple properties.")
.withDefaultValue("boot")
.withDeprecation(null, null));
assertThat(metadata).has(
Metadata.withHint("simple.the-name").withProvider("first", "target", "org.foo").withProvider("second"));
}
@@ -196,8 +213,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
String deprecations = buildPropertyDeprecations(ItemMetadata.newProperty("simple", "wrongName",
"java.lang.String", null, null, null, null, new ItemDeprecation("Lame name.", "simple.the-name")));
ConfigurationMetadata metadata = compile(deprecations, SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class).withDeprecation("Lame name.",
"simple.the-name"));
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class)
.withDeprecation("Lame name.", "simple.the-name"));
}
@Test

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.
@@ -53,7 +53,7 @@ class MetadataStoreTests {
additionalMetadata.createNewFile();
assertThat(this.metadataStore.locateAdditionalMetadataFile(
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
.isEqualTo(additionalMetadata);
.isEqualTo(additionalMetadata);
}
@Test
@@ -67,7 +67,7 @@ class MetadataStoreTests {
additionalMetadata.createNewFile();
assertThat(this.metadataStore.locateAdditionalMetadataFile(
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
.isEqualTo(additionalMetadata);
.isEqualTo(additionalMetadata);
}
@Test
@@ -81,7 +81,7 @@ class MetadataStoreTests {
additionalMetadata.createNewFile();
assertThat(this.metadataStore.locateAdditionalMetadataFile(
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
.isEqualTo(additionalMetadata);
.isEqualTo(additionalMetadata);
}
@Test

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.
@@ -60,7 +60,7 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(config));
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class).fromSource(properties));
assertThat(metadata)
.has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false).fromSource(properties));
.has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false).fromSource(properties));
}
@Test
@@ -73,7 +73,7 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
void invalidMethodConfig() {
ConfigurationMetadata metadata = compile(InvalidMethodConfig.class);
assertThat(metadata)
.has(Metadata.withProperty("something.name", String.class).fromSource(InvalidMethodConfig.class));
.has(Metadata.withProperty("something.name", String.class).fromSource(InvalidMethodConfig.class));
assertThat(metadata).isNotEqualTo(Metadata.withProperty("invalid.name"));
}
@@ -81,22 +81,24 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
void methodAndClassConfig() {
ConfigurationMetadata metadata = compile(MethodAndClassConfig.class);
assertThat(metadata)
.has(Metadata.withProperty("conflict.name", String.class).fromSource(MethodAndClassConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("conflict.flag", Boolean.class).withDefaultValue(false)
.fromSource(MethodAndClassConfig.Foo.class));
.has(Metadata.withProperty("conflict.name", String.class).fromSource(MethodAndClassConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("conflict.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(MethodAndClassConfig.Foo.class));
assertThat(metadata)
.has(Metadata.withProperty("conflict.value", String.class).fromSource(MethodAndClassConfig.class));
.has(Metadata.withProperty("conflict.value", String.class).fromSource(MethodAndClassConfig.class));
}
@Test
void singleConstructorMethodConfig() {
ConfigurationMetadata metadata = compile(SingleConstructorMethodConfig.class);
assertThat(metadata).doesNotHave(Metadata.withProperty("foo.my-service", Object.class)
.fromSource(SingleConstructorMethodConfig.Foo.class));
assertThat(metadata).has(
Metadata.withProperty("foo.name", String.class).fromSource(SingleConstructorMethodConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false)
.fromSource(SingleConstructorMethodConfig.Foo.class));
.fromSource(SingleConstructorMethodConfig.Foo.class));
assertThat(metadata)
.has(Metadata.withProperty("foo.name", String.class).fromSource(SingleConstructorMethodConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(SingleConstructorMethodConfig.Foo.class));
}
@Test
@@ -111,9 +113,12 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(type));
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
.fromSource(DeprecatedMethodConfig.Foo.class).withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false)
.fromSource(DeprecatedMethodConfig.Foo.class).withDeprecation(null, null));
.fromSource(DeprecatedMethodConfig.Foo.class)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(DeprecatedMethodConfig.Foo.class)
.withDeprecation(null, null));
}
@Test
@@ -123,11 +128,12 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(type));
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false)
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
.withDeprecation(null, null));
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
.withDeprecation(null, null));
}
}

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.
@@ -73,13 +73,13 @@ class PropertyDescriptorResolverTests {
PropertyDescriptorResolver resolver = new PropertyDescriptorResolver(metadataEnv);
assertThat(resolver.resolve(type, null).map(PropertyDescriptor::getName)).containsExactly("third",
"second", "first");
assertThat(resolver.resolve(type, null).map(
(descriptor) -> descriptor.getGetter().getEnclosingElement().getSimpleName().toString()))
.containsExactly("HierarchicalProperties", "HierarchicalPropertiesParent",
"HierarchicalPropertiesParent");
assertThat(resolver.resolve(type, null)
.map((descriptor) -> descriptor.resolveItemMetadata("test", metadataEnv))
.map(ItemMetadata::getDefaultValue)).containsExactly("three", "two", "one");
.map((descriptor) -> descriptor.getGetter().getEnclosingElement().getSimpleName().toString()))
.containsExactly("HierarchicalProperties", "HierarchicalPropertiesParent",
"HierarchicalPropertiesParent");
assertThat(resolver.resolve(type, null)
.map((descriptor) -> descriptor.resolveItemMetadata("test", metadataEnv))
.map(ItemMetadata::getDefaultValue)).containsExactly("three", "two", "one");
});
}
@@ -112,7 +112,7 @@ class PropertyDescriptorResolverTests {
process(ImmutableDeducedConstructorBindingProperties.class,
propertyNames((stream) -> assertThat(stream).containsExactly("theName", "flag")));
process(ImmutableDeducedConstructorBindingProperties.class, properties((stream) -> assertThat(stream)
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
}
@Test
@@ -120,7 +120,7 @@ class PropertyDescriptorResolverTests {
process(ImmutableSimpleProperties.class, propertyNames(
(stream) -> assertThat(stream).containsExactly("theName", "flag", "comparator", "counter")));
process(ImmutableSimpleProperties.class, properties((stream) -> assertThat(stream)
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
}
@Test
@@ -128,14 +128,14 @@ class PropertyDescriptorResolverTests {
process(ImmutableClassConstructorBindingProperties.class,
propertyNames((stream) -> assertThat(stream).containsExactly("name", "description")));
process(ImmutableClassConstructorBindingProperties.class, properties((stream) -> assertThat(stream)
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
}
@Test
void propertiesWithAutowiredConstructor() {
process(AutowiredProperties.class, propertyNames((stream) -> assertThat(stream).containsExactly("theName")));
process(AutowiredProperties.class, properties((stream) -> assertThat(stream)
.allMatch((predicate) -> predicate instanceof JavaBeanPropertyDescriptor)));
.allMatch((predicate) -> predicate instanceof JavaBeanPropertyDescriptor)));
}
@Test
@@ -143,7 +143,7 @@ class PropertyDescriptorResolverTests {
process(ImmutableMultiConstructorProperties.class,
propertyNames((stream) -> assertThat(stream).containsExactly("name", "description")));
process(ImmutableMultiConstructorProperties.class, properties((stream) -> assertThat(stream)
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
}
@Test
@@ -154,7 +154,7 @@ class PropertyDescriptorResolverTests {
propertyNames((stream) -> assertThat(stream).containsExactly("name", "description")));
process(org.springframework.boot.configurationsample.immutable.DeprecatedImmutableMultiConstructorProperties.class,
properties((stream) -> assertThat(stream)
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
}
@Test
@@ -197,8 +197,10 @@ class PropertyDescriptorResolverTests {
internalConsumer, new MetadataGenerationEnvironmentFactory());
SourceFile targetSource = SourceFile.forTestClass(target);
List<SourceFile> additionalSource = additionalClasses.stream().map(SourceFile::forTestClass).toList();
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor).withSources(targetSource)
.withSources(additionalSource);
TestCompiler compiler = TestCompiler.forSystem()
.withProcessors(processor)
.withSources(targetSource)
.withSources(additionalSource);
compiler.compile((compiled) -> {
});
}

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.
@@ -45,15 +45,19 @@ public abstract class PropertyDescriptorTests {
}
protected ExecutableElement getMethod(TypeElement element, String name) {
return ElementFilter.methodsIn(element.getEnclosedElements()).stream()
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name)).findFirst()
.orElse(null);
return ElementFilter.methodsIn(element.getEnclosedElements())
.stream()
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name))
.findFirst()
.orElse(null);
}
protected VariableElement getField(TypeElement element, String name) {
return ElementFilter.fieldsIn(element.getEnclosedElements()).stream()
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name)).findFirst()
.orElse(null);
return ElementFilter.fieldsIn(element.getEnclosedElements())
.stream()
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name))
.findFirst()
.orElse(null);
}
protected ItemMetadataAssert assertItemMetadata(MetadataGenerationEnvironment metadataEnv,
@@ -65,8 +69,9 @@ public abstract class PropertyDescriptorTests {
BiConsumer<RoundEnvironmentTester, MetadataGenerationEnvironment> consumer) {
TestableAnnotationProcessor<MetadataGenerationEnvironment> processor = new TestableAnnotationProcessor<>(
consumer, new MetadataGenerationEnvironmentFactory());
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor)
.withSources(SourceFile.forTestClass(target));
TestCompiler compiler = TestCompiler.forSystem()
.withProcessors(processor)
.withSources(SourceFile.forTestClass(target));
compiler.compile((compiled) -> {
});
}

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,8 +84,8 @@ public class TestProject {
*/
public void delete(Class<?> type) {
SourceFile[] newSources = this.sources.stream()
.filter((sourceFile) -> !sourceFile.getPath().equals(SourceFile.forTestClass(type).getPath()))
.toArray(SourceFile[]::new);
.filter((sourceFile) -> !sourceFile.getPath().equals(SourceFile.forTestClass(type).getPath()))
.toArray(SourceFile[]::new);
this.sources = SourceFiles.of(newSources);
}

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.
@@ -44,7 +44,7 @@ class TypeUtilsTests {
void resolveTypeDescriptorOnConcreteClass() {
process(SimpleGenericProperties.class, (roundEnv, typeUtils) -> {
TypeDescriptor typeDescriptor = typeUtils
.resolveTypeDescriptor(roundEnv.getRootElement(SimpleGenericProperties.class));
.resolveTypeDescriptor(roundEnv.getRootElement(SimpleGenericProperties.class));
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
"C");
assertThat(typeDescriptor.resolveGeneric("A")).hasToString(String.class.getName());
@@ -58,7 +58,7 @@ class TypeUtilsTests {
void resolveTypeDescriptorOnIntermediateClass() {
process(AbstractIntermediateGenericProperties.class, (roundEnv, typeUtils) -> {
TypeDescriptor typeDescriptor = typeUtils
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractIntermediateGenericProperties.class));
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractIntermediateGenericProperties.class));
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
"C");
assertThat(typeDescriptor.resolveGeneric("A")).hasToString(String.class.getName());
@@ -71,7 +71,7 @@ class TypeUtilsTests {
void resolveTypeDescriptorWithOnlyGenerics() {
process(AbstractGenericProperties.class, (roundEnv, typeUtils) -> {
TypeDescriptor typeDescriptor = typeUtils
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractGenericProperties.class));
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractGenericProperties.class));
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
"C");
@@ -80,8 +80,9 @@ class TypeUtilsTests {
private void process(Class<?> target, BiConsumer<RoundEnvironmentTester, TypeUtils> consumer) {
TestableAnnotationProcessor<TypeUtils> processor = new TestableAnnotationProcessor<>(consumer, TypeUtils::new);
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor)
.withSources(SourceFile.forTestClass(target));
TestCompiler compiler = TestCompiler.forSystem()
.withProcessors(processor)
.withSources(SourceFile.forTestClass(target));
compiler.compile((compiled) -> {
});
}

View File

@@ -50,8 +50,9 @@ public abstract class AbstractFieldValuesProcessorTests {
@Test
void getFieldValues() throws Exception {
TestProcessor processor = new TestProcessor();
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor)
.withSources(SourceFile.forTestClass(FieldValues.class));
TestCompiler compiler = TestCompiler.forSystem()
.withProcessors(processor)
.withSources(SourceFile.forTestClass(FieldValues.class));
compiler.compile((compiled) -> {
});
Map<String, Object> values = processor.getValues();

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.
@@ -55,8 +55,11 @@ class JsonMarshallerTests {
JsonMarshaller marshaller = new JsonMarshaller();
marshaller.write(metadata, outputStream);
ConfigurationMetadata read = marshaller.read(new ByteArrayInputStream(outputStream.toByteArray()));
assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class).fromSource(InputStream.class)
.withDescription("desc").withDefaultValue("x").withDeprecation("Deprecation comment", "b.c.d"));
assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class)
.fromSource(InputStream.class)
.withDescription("desc")
.withDefaultValue("x")
.withDeprecation("Deprecation comment", "b.c.d"));
assertThat(read).has(Metadata.withProperty("b.c.d"));
assertThat(read).has(Metadata.withProperty("c").withDefaultValue(123));
assertThat(read).has(Metadata.withProperty("d").withDefaultValue(true));
@@ -126,10 +129,10 @@ class JsonMarshallerTests {
null, null, null));
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", "java.lang.Integer", "com.example.Bar", null,
null, null, null));
metadata.add(
ItemMetadata.newProperty("com.example.alpha", "ddd", null, "com.example.Bar", null, null, null, null));
metadata.add(
ItemMetadata.newProperty("com.example.alpha", "ccc", null, "com.example.Foo", null, null, null, null));
metadata
.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, "com.example.Bar", null, null, null, null));
metadata
.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, "com.example.Foo", null, null, null, null));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JsonMarshaller marshaller = new JsonMarshaller();
marshaller.write(metadata, outputStream);

Some files were not shown because too many files have changed in this diff Show More