下面列出了怎么用org.springframework.test.context.junit.jupiter.comics.Dog的API类实例代码及写法,或者点击链接到github查看源代码。
@Autowired
SpringJUnitJupiterAutowiredConstructorInjectionTests(ApplicationContext applicationContext, Person dilbert, Dog dog,
@Value("${enigma}") Integer enigma) {
this.applicationContext = applicationContext;
this.dilbert = dilbert;
this.dog = dog;
this.enigma = enigma;
}
TestConstructorAnnotationIntegrationTests(ApplicationContext applicationContext, Person dilbert, Dog dog,
@Value("${enigma}") Integer enigma) {
this.applicationContext = applicationContext;
this.dilbert = dilbert;
this.dog = dog;
this.enigma = enigma;
}
SpringJUnitJupiterConstructorInjectionTests(ApplicationContext applicationContext, @Autowired Person dilbert,
@Autowired Dog dog, @Value("${enigma}") Integer enigma, TestInfo testInfo) {
this.applicationContext = applicationContext;
this.dilbert = dilbert;
this.dog = dog;
this.enigma = enigma;
this.testInfo = testInfo;
}
@Autowired
SpringJUnitJupiterAutowiredConstructorInjectionTests(ApplicationContext applicationContext, Person dilbert, Dog dog,
@Value("${enigma}") Integer enigma) {
this.applicationContext = applicationContext;
this.dilbert = dilbert;
this.dog = dog;
this.enigma = enigma;
}
SpringJUnitJupiterConstructorInjectionTests(ApplicationContext applicationContext, @Autowired Person dilbert,
@Autowired Dog dog, @Value("${enigma}") Integer enigma, TestInfo testInfo) {
this.applicationContext = applicationContext;
this.dilbert = dilbert;
this.dog = dog;
this.enigma = enigma;
this.testInfo = testInfo;
}
@Autowired
SpringJUnit5AutowiredConstructorInjectionTests(ApplicationContext applicationContext, Person dilbert, Dog dog,
@Value("${enigma}") Integer enigma) {
this.applicationContext = applicationContext;
this.dilbert = dilbert;
this.dog = dog;
this.enigma = enigma;
}
SpringJUnit5ConstructorInjectionTests(ApplicationContext applicationContext, @Autowired Person dilbert,
@Autowired Dog dog, @Value("${enigma}") Integer enigma, TestInfo testInfo) {
this.applicationContext = applicationContext;
this.dilbert = dilbert;
this.dog = dog;
this.enigma = enigma;
this.testInfo = testInfo;
}
@Bean
Dog dogbert() {
return new Dog("Dogbert");
}
@Test
void autowiredParameterByTypeForSingleBean(@Autowired Dog dog) {
assertNotNull(dog, "Dogbert should have been @Autowired by Spring");
assertEquals("Dogbert", dog.getName(), "Dog's name");
}
@Test
void autowiredParameterAsJavaUtilOptional(@Autowired Optional<Dog> dog) {
assertNotNull(dog, "Optional dog should have been @Autowired by Spring");
assertTrue(dog.isPresent(), "Value of Optional should be 'present'");
assertEquals("Dogbert", dog.get().getName(), "Dog's name");
}
@ParameterizedTest
@CsvSource("dogbert, Dogbert")
void dogs(String beanName, String dogName, ApplicationContext context) {
assertEquals(dogName, context.getBean(beanName, Dog.class).getName());
}
@Test
void autowiredParameterByTypeForSingleBean(@Autowired Dog dog) {
assertNotNull(dog, "Dogbert should have been @Autowired by Spring");
assertEquals("Dogbert", dog.getName(), "Dog's name");
}
@Test
void autowiredParameterAsJavaUtilOptional(@Autowired Optional<Dog> dog) {
assertNotNull(dog, "Optional dog should have been @Autowired by Spring");
assertTrue(dog.isPresent(), "Value of Optional should be 'present'");
assertEquals("Dogbert", dog.get().getName(), "Dog's name");
}
@Bean
Dog dogbert() {
return new Dog("Dogbert");
}
@Test
void autowiredParameterByTypeForSingleBean(@Autowired Dog dog) {
assertNotNull(dog, "Dogbert should have been @Autowired by Spring");
assertEquals("Dogbert", dog.getName(), "Dog's name");
}
@Test
void autowiredParameterAsJavaUtilOptional(@Autowired Optional<Dog> dog) {
assertNotNull(dog, "Optional dog should have been @Autowired by Spring");
assertTrue(dog.isPresent(), "Value of Optional should be 'present'");
assertEquals("Dogbert", dog.get().getName(), "Dog's name");
}
@ParameterizedTest
@CsvSource("dogbert, Dogbert")
void dogs(String beanName, String dogName, ApplicationContext context) {
assertEquals(dogName, context.getBean(beanName, Dog.class).getName());
}
@Test
void autowiredParameterByTypeForSingleBean(@Autowired Dog dog) {
assertNotNull(dog, "Dogbert should have been @Autowired by Spring");
assertEquals("Dogbert", dog.getName(), "Dog's name");
}
@Test
void autowiredParameterAsJavaUtilOptional(@Autowired Optional<Dog> dog) {
assertNotNull(dog, "Optional dog should have been @Autowired by Spring");
assertTrue(dog.isPresent(), "Value of Optional should be 'present'");
assertEquals("Dogbert", dog.get().getName(), "Dog's name");
}
@Bean
Dog dogbert() {
return new Dog("Dogbert");
}
@Test
void autowiredParameterByTypeForSingleBean(@Autowired Dog dog) {
assertNotNull(dog, "Dogbert should have been @Autowired by Spring");
assertEquals("Dogbert", dog.getName(), "Dog's name");
}
@Test
void autowiredParameterAsJavaUtilOptional(@Autowired Optional<Dog> dog) {
assertNotNull(dog, "Optional dog should have been @Autowired by Spring");
assertTrue(dog.isPresent(), "Value of Optional should be 'present'");
assertEquals("Dogbert", dog.get().getName(), "Dog's name");
}