|
@@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
|
|
|
|
|
+import javax.swing.*;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -18,11 +19,34 @@ import java.util.Map;
|
|
|
//@Import(cn.hutool.extra.spring.SpringUtil.class)
|
|
//@Import(cn.hutool.extra.spring.SpringUtil.class)
|
|
|
public class SpringUtilTest {
|
|
public class SpringUtilTest {
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 注册bean
|
|
|
|
|
+ *
|
|
|
|
|
+ * 为了保证顺序采用顺序abcdef...形式命名方法
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void a() {
|
|
|
|
|
+ Demo2 registerBean = new Demo2();
|
|
|
|
|
+ registerBean.id = 123;
|
|
|
|
|
+ registerBean.name = "222";
|
|
|
|
|
+ SpringUtil.registerBean("registerBean", registerBean);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 验证注册的bean
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void b() {
|
|
|
|
|
+ Demo2 registerBean = SpringUtil.getBean("registerBean");
|
|
|
|
|
+ Assert.assertEquals(123, registerBean.id);
|
|
|
|
|
+ Assert.assertEquals("222", registerBean.name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void getBeanTest(){
|
|
public void getBeanTest(){
|
|
|
final Demo2 testDemo = SpringUtil.getBean("testDemo");
|
|
final Demo2 testDemo = SpringUtil.getBean("testDemo");
|
|
|
- Assert.assertEquals(12345, testDemo.getId());
|
|
|
|
|
- Assert.assertEquals("test", testDemo.getName());
|
|
|
|
|
|
|
+ Assert.assertEquals(12345, testDemo.id);
|
|
|
|
|
+ Assert.assertEquals("test", testDemo.name);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -41,8 +65,8 @@ public class SpringUtilTest {
|
|
|
@Bean(name="testDemo")
|
|
@Bean(name="testDemo")
|
|
|
public Demo2 generateDemo() {
|
|
public Demo2 generateDemo() {
|
|
|
Demo2 demo = new Demo2();
|
|
Demo2 demo = new Demo2();
|
|
|
- demo.setId(12345);
|
|
|
|
|
- demo.setName("test");
|
|
|
|
|
|
|
+ demo.id = 12345;
|
|
|
|
|
+ demo.name= "test";
|
|
|
return demo;
|
|
return demo;
|
|
|
}
|
|
}
|
|
|
|
|
|