|
| 1 | +/* |
| 2 | + * Copyright 2019-2021 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 | + |
1 | 17 | package com.example.validator;
|
2 | 18 |
|
3 | 19 | import org.junit.jupiter.api.Test;
|
4 | 20 |
|
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
5 | 22 | import org.springframework.boot.test.context.SpringBootTest;
|
| 23 | +import org.springframework.context.support.GenericApplicationContext; |
| 24 | +import org.springframework.validation.Validator; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
6 | 27 |
|
7 | 28 | @SpringBootTest
|
8 |
| -public class ValidatorApplicationTests { |
| 29 | +class ValidatorApplicationTests { |
| 30 | + |
| 31 | + @Autowired(required = false) |
| 32 | + private Validator validator; |
| 33 | + |
| 34 | + @Autowired |
| 35 | + private GenericApplicationContext applicationContext; |
| 36 | + |
| 37 | + @Test |
| 38 | + void validatorHasPrimaryFlag() { |
| 39 | + assertThat(this.validator).isNotNull(); |
| 40 | + assertThat(this.applicationContext.containsBeanDefinition("defaultValidator")).isTrue(); |
| 41 | + assertThat(this.applicationContext.getBeanDefinition("defaultValidator").isPrimary()).isTrue(); |
| 42 | + } |
9 | 43 |
|
10 | 44 | @Test
|
11 |
| - public void contextLoads() { |
| 45 | + void twoValidatorsAreDefined() { |
| 46 | + assertThat(this.applicationContext.getBeansOfType(Validator.class)) |
| 47 | + .containsOnlyKeys("defaultValidator", "mvcValidator"); |
12 | 48 | }
|
13 | 49 |
|
14 | 50 | }
|
0 commit comments