Commit be7d6971 authored by Michal Mlak's avatar Michal Mlak Committed by Phillip Webb

Add a FailureAnalyzer for ConfigDataNotFound

Add a `FailureAnalyzer` to deal with `ConfigDataNotFoundException`.

See gh-23633
parent 1cf9fc10
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<ConfigDataLocationNotFoundException> {
@Override
protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataLocationNotFoundException cause) {
return new FailureAnalysis(cause.getMessage(), null, cause);
}
}
......@@ -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=\
......
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 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()).isNull();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment