-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from weihubeats/add-spring-boot-nebula-all
add SpringBeanUtilsTest
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/SpringBeanUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.nebula.web.common.utils; | ||
|
||
import com.nebula.web.common.autoconfigure.NebulaWebCommonAutoConfiguration; | ||
import java.util.Objects; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.NoSuchBeanDefinitionException; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrowsExactly; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* @author : wh | ||
* @date : 2024/3/28 09:45 | ||
* @description: | ||
*/ | ||
@SpringBootTest(classes = SpringBeanUtilsTest.TestConfig.class) | ||
public class SpringBeanUtilsTest { | ||
|
||
@Test | ||
public void getBean() { | ||
Object bean = SpringBeanUtils.getBean("testBean"); | ||
assertTrue(bean instanceof TestBean); | ||
TestBean bean1 = SpringBeanUtils.getBean(TestBean.class); | ||
assertTrue(Objects.nonNull(bean1)); | ||
assertThrowsExactly(NoSuchBeanDefinitionException.class, () -> SpringBeanUtils.getBean(NoTestBean.class)); | ||
|
||
} | ||
|
||
static final class TestBean { | ||
} | ||
|
||
static final class NoTestBean { | ||
} | ||
|
||
@Configuration | ||
@EnableAutoConfiguration | ||
@ImportAutoConfiguration({NebulaWebCommonAutoConfiguration.class}) | ||
public static class TestConfig { | ||
|
||
@Bean | ||
public TestBean testBean() { | ||
return new TestBean(); | ||
|
||
} | ||
|
||
} | ||
|
||
} |