Introduce builder API for AOT processor Settings

Closes gh-29341
This commit is contained in:
Sam Brannen
2022-10-18 16:33:16 +02:00
parent cb44e09694
commit eadb003a8d
4 changed files with 255 additions and 76 deletions

View File

@@ -0,0 +1,126 @@
/*
* Copyright 2002-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.aot;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.context.aot.AbstractAotProcessor.Settings;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link AbstractAotProcessor}, settings, and builder.
*
* @author Sam Brannen
* @since 6.0
*/
class AotProcessorTests {
@Test
void builderRejectsMissingSourceOutput() {
assertThatIllegalArgumentException()
.isThrownBy(() -> Settings.builder().build())
.withMessageContaining("'sourceOutput'");
}
@Test
void builderRejectsMissingResourceOutput(@TempDir Path tempDir) {
assertThatIllegalArgumentException()
.isThrownBy(() -> Settings.builder().sourceOutput(tempDir).build())
.withMessageContaining("'resourceOutput'");
}
@Test
void builderRejectsMissingClassOutput(@TempDir Path tempDir) {
assertThatIllegalArgumentException()
.isThrownBy(() -> Settings.builder()
.sourceOutput(tempDir)
.resourceOutput(tempDir)
.build())
.withMessageContaining("'classOutput'");
}
@Test
void builderRejectsMissingGroupdId(@TempDir Path tempDir) {
assertThatIllegalArgumentException()
.isThrownBy(() -> Settings.builder()
.sourceOutput(tempDir)
.resourceOutput(tempDir)
.classOutput(tempDir)
.build())
.withMessageContaining("'groupId'");
}
@Test
void builderRejectsEmptyGroupdId(@TempDir Path tempDir) {
assertThatIllegalArgumentException()
.isThrownBy(() -> Settings.builder()
.sourceOutput(tempDir)
.resourceOutput(tempDir)
.classOutput(tempDir)
.groupId(" ")
.build())
.withMessageContaining("'groupId'");
}
@Test
void builderRejectsMissingArtifactId(@TempDir Path tempDir) {
assertThatIllegalArgumentException()
.isThrownBy(() -> Settings.builder()
.sourceOutput(tempDir)
.resourceOutput(tempDir)
.classOutput(tempDir)
.groupId("my-group")
.build())
.withMessageContaining("'artifactId'");
}
@Test
void builderRejectsEmptyArtifactId(@TempDir Path tempDir) {
assertThatIllegalArgumentException()
.isThrownBy(() -> Settings.builder()
.sourceOutput(tempDir)
.resourceOutput(tempDir)
.classOutput(tempDir)
.groupId("my-group")
.artifactId(" ")
.build())
.withMessageContaining("'artifactId'");
}
@Test
void builderAcceptsRequiredSettings(@TempDir Path tempDir) {
Settings settings = Settings.builder()
.sourceOutput(tempDir)
.resourceOutput(tempDir)
.classOutput(tempDir)
.groupId("my-group")
.artifactId("my-artifact")
.build();
assertThat(settings).isNotNull();
assertThat(settings.getSourceOutput()).isEqualTo(tempDir);
assertThat(settings.getResourceOutput()).isEqualTo(tempDir);
assertThat(settings.getClassOutput()).isEqualTo(tempDir);
assertThat(settings.getGroupId()).isEqualTo("my-group");
assertThat(settings.getArtifactId()).isEqualTo("my-artifact");
}
}

View File

@@ -128,12 +128,13 @@ class ContextAotProcessorTests {
private static Settings createSettings(Path sourceOutput, Path resourceOutput,
Path classOutput, String groupId, String artifactId) {
return new Settings()
.setSourceOutput(sourceOutput)
.setResourceOutput(resourceOutput)
.setClassOutput(classOutput)
.setArtifactId(artifactId)
.setGroupId(groupId);
return Settings.builder()
.sourceOutput(sourceOutput)
.resourceOutput(resourceOutput)
.classOutput(classOutput)
.artifactId(artifactId)
.groupId(groupId)
.build();
}
@Override