1
0

Code-Optimierungen

This commit is contained in:
2026-04-13 07:21:31 +02:00
parent f0538fa247
commit 59f13608cc
3 changed files with 16 additions and 15 deletions

View File

@@ -307,13 +307,13 @@ public class StartConfigurationValidator {
* or exists and is a directory.
*/
private void validateOptionalExistingDirectory(Path directoryPath, String fieldName, List<String> errors) {
if (directoryPath != null && !directoryPath.toString().isBlank() && Files.exists(directoryPath)) {
if (!Files.isDirectory(directoryPath)) {
errors.add("- " + fieldName + ": exists but is not a directory: " + directoryPath);
}
}
// If it doesn't exist yet, that's acceptable - we don't auto-create
if (directoryPath != null
&& !directoryPath.toString().isBlank()
&& Files.exists(directoryPath)
&& !Files.isDirectory(directoryPath)) {
errors.add("- " + fieldName + ": exists but is not a directory: " + directoryPath);
}
// If it doesn't exist yet, that's acceptable - we don't auto-create
}
/**

View File

@@ -8,6 +8,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import de.gecheckt.pdf.umbenenner.application.config.provider.MultiProviderConfiguration;
import de.gecheckt.pdf.umbenenner.application.config.startup.StartConfiguration;
@@ -45,7 +46,7 @@ public class PropertiesConfigurationPortAdapter implements ConfigurationPort {
*
* @param environmentLookup a function that looks up environment variables by name
*/
public PropertiesConfigurationPortAdapter(Function<String, String> environmentLookup) {
public PropertiesConfigurationPortAdapter(UnaryOperator<String> environmentLookup) {
this(environmentLookup, Paths.get(DEFAULT_CONFIG_FILE_PATH));
}
@@ -69,7 +70,7 @@ public class PropertiesConfigurationPortAdapter implements ConfigurationPort {
* @param environmentLookup a function that looks up environment variables by name
* @param configFilePath the path to the configuration properties file
*/
public PropertiesConfigurationPortAdapter(Function<String, String> environmentLookup, Path configFilePath) {
public PropertiesConfigurationPortAdapter(UnaryOperator<String> environmentLookup, Path configFilePath) {
this.environmentLookup = environmentLookup;
this.configFilePath = configFilePath;
}

View File

@@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -26,7 +26,7 @@ import de.gecheckt.pdf.umbenenner.application.config.provider.AiProviderFamily;
*/
class PropertiesConfigurationPortAdapterTest {
private Function<String, String> emptyEnvLookup;
private UnaryOperator<String> emptyEnvLookup;
@TempDir
Path tempDir;
@@ -84,7 +84,7 @@ class PropertiesConfigurationPortAdapterTest {
void loadConfiguration_rejectsBlankApiKeyWhenEnvVarIsNull() throws Exception {
Path configFile = createConfigFile("no-api-key.properties");
Function<String, String> envLookup = key -> null;
UnaryOperator<String> envLookup = key -> null;
PropertiesConfigurationPortAdapter adapter = new PropertiesConfigurationPortAdapter(envLookup, configFile);
@@ -98,7 +98,7 @@ class PropertiesConfigurationPortAdapterTest {
void loadConfiguration_rejectsBlankApiKeyWhenEnvVarIsEmpty() throws Exception {
Path configFile = createConfigFile("no-api-key.properties");
Function<String, String> envLookup = key -> "";
UnaryOperator<String> envLookup = key -> "";
PropertiesConfigurationPortAdapter adapter = new PropertiesConfigurationPortAdapter(envLookup, configFile);
@@ -112,7 +112,7 @@ class PropertiesConfigurationPortAdapterTest {
void loadConfiguration_rejectsBlankApiKeyWhenEnvVarIsBlank() throws Exception {
Path configFile = createConfigFile("no-api-key.properties");
Function<String, String> envLookup = key -> " ";
UnaryOperator<String> envLookup = key -> " ";
PropertiesConfigurationPortAdapter adapter = new PropertiesConfigurationPortAdapter(envLookup, configFile);
@@ -126,7 +126,7 @@ class PropertiesConfigurationPortAdapterTest {
void loadConfiguration_envVarOverridesPropertiesApiKey() throws Exception {
Path configFile = createConfigFile("valid-config.properties");
Function<String, String> envLookup = key -> {
UnaryOperator<String> envLookup = key -> {
if (MultiProviderConfigurationParser.ENV_OPENAI_API_KEY.equals(key)) {
return "env-api-key-override";
}