From 6a2e579b51213f8776514d7b1b19f57f982680ab Mon Sep 17 00:00:00 2001 From: Michal Mlak Date: Sun, 11 Oct 2020 19:18:33 +0100 Subject: [PATCH 1/2] Implements FailureAnalyzer for ConfigDataLocationNotFoundException. Adds unit tests and adds to spring.factories. Fixes gh-23429 --- ...ationNotFoundExceptionFailureAnalyzer.java | 23 ++++++++++++++ .../main/resources/META-INF/spring.factories | 3 +- ...NotFoundExceptionFailureAnalyzerTests.java | 31 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzer.java create mode 100644 spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzerTests.java diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzer.java new file mode 100644 index 000000000000..3a426e8364f1 --- /dev/null +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzer.java @@ -0,0 +1,23 @@ +package org.springframework.boot.context.config; + +import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; +import org.springframework.boot.diagnostics.FailureAnalysis; + +/** + * + * An implementation of {@link AbstractFailureAnalyzer} to analyze failures caused by + * {@link ConfigDataLocationNotFoundException}. + * + * @author Michal Mlak + */ +public class ConfigDataLocationNotFoundExceptionFailureAnalyzer + extends AbstractFailureAnalyzer { + + private static final String ACTION = "Make sure a config file is present at the configured path or the path itself is correct."; + + @Override + protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataLocationNotFoundException cause) { + return new FailureAnalysis(cause.getMessage(), ACTION, cause); + } + +} diff --git a/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories index d460701d02f5..51b68fd29a28 100644 --- a/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories @@ -74,7 +74,8 @@ org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\ org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer,\ org.springframework.boot.diagnostics.analyzer.PatternParseFailureAnalyzer,\ -org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer +org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer,\ +org.springframework.boot.context.config.ConfigDataLocationNotFoundExceptionFailureAnalyzer # Failure Analysis Reporters org.springframework.boot.diagnostics.FailureAnalysisReporter=\ diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzerTests.java new file mode 100644 index 000000000000..8654f30e14a8 --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzerTests.java @@ -0,0 +1,31 @@ +package org.springframework.boot.context.config; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.diagnostics.FailureAnalysis; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +/** + * + * Tests for {@link ConfigDataLocationNotFoundExceptionFailureAnalyzer} + * + * @author Michal Mlak + */ +class ConfigDataLocationNotFoundExceptionFailureAnalyzerTests { + + private final ConfigDataLocationNotFoundExceptionFailureAnalyzer analyzer = new ConfigDataLocationNotFoundExceptionFailureAnalyzer(); + + @Test + void failureAnalysisfor() { + ConfigDataLocation location = mock(ConfigDataLocation.class); + ConfigDataLocationNotFoundException exception = new ConfigDataLocationNotFoundException(location); + + FailureAnalysis result = analyzer.analyze(exception); + + assertThat(result.getDescription()).isEqualTo("Config data location '" + location + "' does not exist"); + assertThat(result.getAction()) + .isEqualTo("Make sure a config file is present at the configured path or the path itself is correct."); + } + +} \ No newline at end of file From 0b5ec9faa64bab3d21f7af9d2af503f4fbd56ca2 Mon Sep 17 00:00:00 2001 From: Michal Mlak Date: Sun, 11 Oct 2020 19:26:21 +0100 Subject: [PATCH 2/2] Changes action to null, as it seems obvious what needs to be done. --- .../ConfigDataLocationNotFoundExceptionFailureAnalyzer.java | 4 +--- ...figDataLocationNotFoundExceptionFailureAnalyzerTests.java | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzer.java index 3a426e8364f1..589edf784b4e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzer.java @@ -13,11 +13,9 @@ public class ConfigDataLocationNotFoundExceptionFailureAnalyzer extends AbstractFailureAnalyzer { - private static final String ACTION = "Make sure a config file is present at the configured path or the path itself is correct."; - @Override protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataLocationNotFoundException cause) { - return new FailureAnalysis(cause.getMessage(), ACTION, cause); + return new FailureAnalysis(cause.getMessage(), null, cause); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzerTests.java index 8654f30e14a8..bcc2063adde7 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationNotFoundExceptionFailureAnalyzerTests.java @@ -17,15 +17,14 @@ class ConfigDataLocationNotFoundExceptionFailureAnalyzerTests { private final ConfigDataLocationNotFoundExceptionFailureAnalyzer analyzer = new ConfigDataLocationNotFoundExceptionFailureAnalyzer(); @Test - void failureAnalysisfor() { + void failureAnalysisForConfigDataLocationNotFound() { ConfigDataLocation location = mock(ConfigDataLocation.class); ConfigDataLocationNotFoundException exception = new ConfigDataLocationNotFoundException(location); FailureAnalysis result = analyzer.analyze(exception); assertThat(result.getDescription()).isEqualTo("Config data location '" + location + "' does not exist"); - assertThat(result.getAction()) - .isEqualTo("Make sure a config file is present at the configured path or the path itself is correct."); + assertThat(result.getAction()).isNull(); } } \ No newline at end of file