/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
spring-5/src/test/java/com/baeldung/functional/BeanRegistrationIntegrationTest.java
42 строки
2 KB
Amit Pandey
JAVA-29185 :- Upgrade Spring 5 to boot 3. (#16141)
18 мар 2024, 21:43
Не верифицирован
18 мар 2024, 21:43
68db1db
Код
Авторство
О чём код?
package com.baeldung.functional; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.context.support.GenericWebApplicationContext; import com.baeldung.Spring5Application; @RunWith(SpringRunner.class) @SpringBootTest(classes = Spring5Application.class) public class BeanRegistrationIntegrationTest { @Autowired private GenericWebApplicationContext context; @Test public void whenRegisterBean_thenOk() { context.registerBean(MyService.class, MyService::new); MyService myService = (MyService) context.getBean("com.baeldung.functional.MyService"); assertTrue(myService.getRandomNumber() < 10); } @Test public void whenRegisterBeanWithName_thenOk() { context.registerBean("mySecondService", MyService.class, MyService::new); MyService mySecondService = (MyService) context.getBean("mySecondService"); assertTrue(mySecondService.getRandomNumber() < 10); } @Test public void whenRegisterBeanWithCallback_thenOk() { context.registerBean("myCallbackService", MyService.class, MyService::new, bd -> bd.setAutowireCandidate(false)); MyService myCallbackService = (MyService) context.getBean("myCallbackService"); assertTrue(myCallbackService.getRandomNumber() < 10); } }