cleanup work and test naming
This commit is contained in:
+2
-4
@@ -5,19 +5,17 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class ConstructorBasedBeanInjectionWithJavaConfigTest {
|
||||
public class ConstructorBasedBeanInjectionWithJavaConfigIntegrationTest {
|
||||
private static final String HELM_NAME = "HelmBrand";
|
||||
|
||||
@Test
|
||||
public void givenJavaConfigFile_whenUsingConstructorBasedBeanInjection_thenCorrectHelmName() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ConstructorBasedShipConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
Ship ship = ctx.getBean(Ship.class);
|
||||
|
||||
Assert.assertEquals(HELM_NAME, ship.getHelm()
|
||||
.getBrandOfHelm());
|
||||
Assert.assertEquals(HELM_NAME, ship.getHelm().getBrandOfHelm());
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class ConstructorBasedBeanInjectionWithXMLConfigTest {
|
||||
public class ConstructorBasedBeanInjectionWithXMLConfigIntegrationTest {
|
||||
|
||||
private static final String HELM_NAME = "HelmBrand";
|
||||
|
||||
@@ -14,7 +14,6 @@ public class ConstructorBasedBeanInjectionWithXMLConfigTest {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanInjection-constructor.xml");
|
||||
|
||||
final Ship shipConstructorBean = (Ship) applicationContext.getBean("ship");
|
||||
Assert.assertEquals(HELM_NAME, shipConstructorBean.getHelm()
|
||||
.getBrandOfHelm());
|
||||
Assert.assertEquals(HELM_NAME, shipConstructorBean.getHelm().getBrandOfHelm());
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -5,7 +5,7 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class SetterBasedBeanInjectionWithJavaConfigTest {
|
||||
public class SetterBasedBeanInjectionWithJavaConfigIntegrationTest {
|
||||
|
||||
private static final String HELM_NAME = "HelmBrand";
|
||||
|
||||
@@ -18,7 +18,6 @@ public class SetterBasedBeanInjectionWithJavaConfigTest {
|
||||
|
||||
Ship ship = ctx.getBean(Ship.class);
|
||||
|
||||
Assert.assertEquals(HELM_NAME, ship.getHelm()
|
||||
.getBrandOfHelm());
|
||||
Assert.assertEquals(HELM_NAME, ship.getHelm().getBrandOfHelm());
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class SetterBasedBeanInjectionWithXMLConfigTest {
|
||||
public class SetterBasedBeanInjectionWithXMLConfigIntegrationTest {
|
||||
|
||||
private static final String HELM_NAME = "HelmBrand";
|
||||
|
||||
@@ -14,7 +14,6 @@ public class SetterBasedBeanInjectionWithXMLConfigTest {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanInjection-setter.xml");
|
||||
|
||||
final Ship shipSetterBean = (Ship) applicationContext.getBean("ship");
|
||||
Assert.assertEquals(HELM_NAME, shipSetterBean.getHelm()
|
||||
.getBrandOfHelm());
|
||||
Assert.assertEquals(HELM_NAME, shipSetterBean.getHelm().getBrandOfHelm());
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,17 @@ public class TenantScopeTest {
|
||||
@Test
|
||||
public final void whenRegisterScopeAndBeans_thenContextContainsFooAndBar() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
try{
|
||||
try {
|
||||
ctx.register(TenantScopeConfig.class);
|
||||
ctx.register(TenantBeansConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
|
||||
TenantBean foo = (TenantBean) ctx.getBean("foo", TenantBean.class);
|
||||
foo.sayHello();
|
||||
TenantBean bar = (TenantBean) ctx.getBean("bar", TenantBean.class);
|
||||
bar.sayHello();
|
||||
Map<String, TenantBean> foos = ctx.getBeansOfType(TenantBean.class);
|
||||
|
||||
|
||||
assertThat(foo, not(equalTo(bar)));
|
||||
assertThat(foos.size(), equalTo(2));
|
||||
assertTrue(foos.containsValue(foo));
|
||||
@@ -34,40 +34,38 @@ public class TenantScopeTest {
|
||||
|
||||
BeanDefinition fooDefinition = ctx.getBeanDefinition("foo");
|
||||
BeanDefinition barDefinition = ctx.getBeanDefinition("bar");
|
||||
|
||||
|
||||
assertThat(fooDefinition.getScope(), equalTo("tenant"));
|
||||
assertThat(barDefinition.getScope(), equalTo("tenant"));
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public final void whenComponentScan_thenContextContainsFooAndBar() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
try{
|
||||
try {
|
||||
ctx.scan("org.baeldung.customscope");
|
||||
ctx.refresh();
|
||||
|
||||
|
||||
TenantBean foo = (TenantBean) ctx.getBean("foo", TenantBean.class);
|
||||
foo.sayHello();
|
||||
TenantBean bar = (TenantBean) ctx.getBean("bar", TenantBean.class);
|
||||
bar.sayHello();
|
||||
Map<String, TenantBean> foos = ctx.getBeansOfType(TenantBean.class);
|
||||
|
||||
|
||||
assertThat(foo, not(equalTo(bar)));
|
||||
assertThat(foos.size(), equalTo(2));
|
||||
assertTrue(foos.containsValue(foo));
|
||||
assertTrue(foos.containsValue(bar));
|
||||
|
||||
|
||||
BeanDefinition fooDefinition = ctx.getBeanDefinition("foo");
|
||||
BeanDefinition barDefinition = ctx.getBeanDefinition("bar");
|
||||
|
||||
|
||||
assertThat(fooDefinition.getScope(), equalTo("tenant"));
|
||||
assertThat(barDefinition.getScope(), equalTo("tenant"));
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ public class SquareCalculatorTest {
|
||||
public void whenCalculatingSquareValueOnce_thenCacheDontHaveValues() {
|
||||
for (int i = 10; i < 15; i++) {
|
||||
assertFalse(cacheHelper.getSquareNumberCache().containsKey(i));
|
||||
System.out.println("Square value of " + i + " is: "
|
||||
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
|
||||
System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,14 +29,12 @@ public class SquareCalculatorTest {
|
||||
public void whenCalculatingSquareValueAgain_thenCacheHasAllValues() {
|
||||
for (int i = 10; i < 15; i++) {
|
||||
assertFalse(cacheHelper.getSquareNumberCache().containsKey(i));
|
||||
System.out.println("Square value of " + i + " is: "
|
||||
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
|
||||
System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n");
|
||||
}
|
||||
|
||||
for (int i = 10; i < 15; i++) {
|
||||
assertTrue(cacheHelper.getSquareNumberCache().containsKey(i));
|
||||
System.out.println("Square value of " + i + " is: "
|
||||
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
|
||||
System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { ThreadPoolTaskSchedulerConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class ThreadPoolTaskSchedulerIntegrationTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testThreadPoolTaskSchedulerAnnotation() throws InterruptedException {
|
||||
Thread.sleep(2550);
|
||||
|
||||
Reference in New Issue
Block a user