Merge branch '2.7.x'

pull/30674/head
Andy Wilkinson 3 years ago
commit 7e97073994

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@ -110,7 +110,7 @@ public class BuildInfo extends ConventionTask {
private Map<String, String> coerceToStringValues(Map<String, Object> input) {
Map<String, String> output = new HashMap<>();
input.forEach((key, value) -> output.put(key, value.toString()));
input.forEach((key, value) -> output.put(key, (value != null) ? value.toString() : null));
return output;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@ -33,6 +33,7 @@ import org.springframework.boot.gradle.junit.GradleProjectBuilder;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Tests for {@link BuildInfo}.
@ -186,6 +187,14 @@ class BuildInfoTests {
assertThat(buildInfoProperties(task)).containsEntry("build.b", "bravo");
}
@Test
void nullAdditionalPropertyProducesInformativeFailure() {
BuildInfo task = createTask(createProject("test"));
task.getProperties().getAdditional().put("a", null);
assertThatThrownBy(() -> buildInfoProperties(task))
.hasMessage("Additional property 'a' is illegal as its value is null");
}
private Project createProject(String projectName) {
File projectDir = new File(this.temp, projectName);
Project project = GradleProjectBuilder.builder().withProjectDir(projectDir).withName(projectName).build();

Loading…
Cancel
Save