cleanup work for tests

This commit is contained in:
Eugen Paraschiv
2018-03-04 17:52:56 +02:00
parent 4a489e4afc
commit 5fd8e4293e
8 changed files with 10 additions and 20 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 BeanRegistrationIntegrationTest {
@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);
}
}