@Lazy annotation (#3809)

This commit is contained in:
Mher Baghinyan
2018-03-17 13:30:44 +04:00
committed by Grzegorz Piwowarek
parent 4c0a39a342
commit 7eb74160f1
5 changed files with 100 additions and 0 deletions
@@ -0,0 +1,37 @@
package com.baeldung.Lazy;
import com.baeldung.lazy.AppConfig;
import com.baeldung.lazy.Country;
import com.baeldung.lazy.Region;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class LazyAnnotationUnitTest {
@Test
public void givenLazyAnnotation_whenConfigClass_thenLazyAll() {
// Add @Lazy to AppConfig.class while testing
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AppConfig.class);
ctx.refresh();
ctx.getBean(Region.class);
ctx.getBean(Country.class);
}
@Test
public void givenLazyAnnotation_whenAutowire_thenLazyBean() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AppConfig.class);
ctx.refresh();
Region region = ctx.getBean(Region.class);
region.getCityInstance();
}
@Test
public void givenLazyAnnotation_whenBeanConfig_thenLazyBean() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AppConfig.class);
ctx.refresh();
ctx.getBean(Region.class);
}
}