|
| 1 | +/* |
| 2 | + * Copyright 2012-2019 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.diagnostics.analyzer; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
| 22 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 23 | +import org.springframework.boot.testsupport.classpath.ClassPathExclusions; |
| 24 | +import org.springframework.boot.testsupport.classpath.ClassPathOverrides; |
| 25 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 26 | +import org.springframework.validation.annotation.Validated; |
| 27 | + |
| 28 | +import static org.assertj.core.api.Assertions.assertThat; |
| 29 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 30 | + |
| 31 | +/** |
| 32 | + * Tests for {@link ValidationExceptionFailureAnalyzer} |
| 33 | + * |
| 34 | + * @author Andy Wilkinson |
| 35 | + */ |
| 36 | +@ClassPathExclusions("hibernate-validator-*.jar") |
| 37 | +@ClassPathOverrides("javax.validation:validation-api:2.0.1.Final") |
| 38 | +class JavaxApiValidationExceptionFailureAnalyzerTests2 { |
| 39 | + |
| 40 | + @Test |
| 41 | + void validatedPropertiesTest() { |
| 42 | + assertThatExceptionOfType(Exception.class) |
| 43 | + .isThrownBy(() -> new AnnotationConfigApplicationContext(TestConfiguration.class).close()) |
| 44 | + .satisfies((ex) -> assertThat(new ValidationExceptionFailureAnalyzer().analyze(ex)).isNotNull()); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void nonValidatedPropertiesTest() { |
| 49 | + new AnnotationConfigApplicationContext(NonValidatedTestConfiguration.class).close(); |
| 50 | + } |
| 51 | + |
| 52 | + @EnableConfigurationProperties(TestProperties.class) |
| 53 | + static class TestConfiguration { |
| 54 | + |
| 55 | + TestConfiguration(TestProperties testProperties) { |
| 56 | + } |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + @ConfigurationProperties("test") |
| 61 | + @Validated |
| 62 | + static class TestProperties { |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | + @EnableConfigurationProperties(NonValidatedTestProperties.class) |
| 67 | + static class NonValidatedTestConfiguration { |
| 68 | + |
| 69 | + NonValidatedTestConfiguration(NonValidatedTestProperties testProperties) { |
| 70 | + } |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + @ConfigurationProperties("test") |
| 75 | + static class NonValidatedTestProperties { |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | +} |
0 commit comments