Merge remote-tracking branch 'upstream/master' into earth001_BAEL-1121

This commit is contained in:
juan
2017-09-13 23:14:33 -03:00
494 changed files with 14952 additions and 645 deletions

View File

@@ -0,0 +1,42 @@
package com.baeldung.functional;
import static org.junit.Assert.*;
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 BeanRegistrationTest {
@Autowired
private GenericWebApplicationContext context;
@Test
public void whenRegisterBean_thenOk() {
context.registerBean(MyService.class, () -> new MyService());
MyService myService = (MyService) context.getBean("com.baeldung.functional.MyService");
assertTrue(myService.getRandomNumber() < 10);
}
@Test
public void whenRegisterBeanWithName_thenOk() {
context.registerBean("mySecondService", MyService.class, () -> new MyService());
MyService mySecondService = (MyService) context.getBean("mySecondService");
assertTrue(mySecondService.getRandomNumber() < 10);
}
@Test
public void whenRegisterBeanWithCallback_thenOk() {
context.registerBean("myCallbackService", MyService.class, () -> new MyService(), bd -> bd.setAutowireCandidate(false));
MyService myCallbackService = (MyService) context.getBean("myCallbackService");
assertTrue(myCallbackService.getRandomNumber() < 10);
}
}