Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit b6d6751

Browse files
committed
Test that primary flag is properly set on default validator
Closes gh-1243
1 parent 1d4db62 commit b6d6751

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,50 @@
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+
117
package com.example.validator;
218

319
import org.junit.jupiter.api.Test;
420

21+
import org.springframework.beans.factory.annotation.Autowired;
522
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;
627

728
@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+
}
943

1044
@Test
11-
public void contextLoads() {
45+
void twoValidatorsAreDefined() {
46+
assertThat(this.applicationContext.getBeansOfType(Validator.class))
47+
.containsOnlyKeys("defaultValidator", "mvcValidator");
1248
}
1349

1450
}

0 commit comments

Comments
 (0)