-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
5 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
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
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
71 changes: 71 additions & 0 deletions
71
src/test/java/com/codeus/winter/config/impl/BeanDefinitionRegistryImplTest.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,71 @@ | ||
package com.codeus.winter.config.impl; | ||
|
||
import com.codeus.winter.config.BeanDefinition; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class BeanDefinitionRegistryImplTest { | ||
private BeanDefinitionRegistryImpl beanFactory; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
beanFactory = new BeanDefinitionRegistryImpl(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should create a bean using a mocked BeanDefinition") | ||
void testCreateBeanWithMockBeanDefinition() { | ||
BeanDefinition mockBeanDefinition = mock(BeanDefinition.class); | ||
when(mockBeanDefinition.getBeanClassName()).thenReturn("test.MyTestBean"); | ||
when(mockBeanDefinition.isSingleton()).thenReturn(true); | ||
|
||
beanFactory.registerBeanDefinition("testBean", mockBeanDefinition); | ||
|
||
Object bean = beanFactory.getBeanDefinition("testBean"); | ||
assertNotNull(bean, "Bean should not be null"); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should register and retrieve a BeanDefinition successfully") | ||
void testRegisterAndRetrieveBeanDefinition() { | ||
BeanDefinition mockBeanDefinition = mock(BeanDefinition.class); | ||
when(mockBeanDefinition.getBeanClassName()).thenReturn("test.MyTestBean"); | ||
|
||
beanFactory.registerBeanDefinition("testBean", mockBeanDefinition); | ||
|
||
BeanDefinition retrievedDefinition = beanFactory.getBeanDefinition("testBean"); | ||
|
||
assertNotNull(retrievedDefinition, "BeanDefinition should not be null"); | ||
assertEquals("test.MyTestBean", retrievedDefinition.getBeanClassName()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should check if a BeanDefinition exists in the registry") | ||
void testContainsBeanDefinition() { | ||
BeanDefinition mockBeanDefinition = mock(BeanDefinition.class); | ||
|
||
beanFactory.registerBeanDefinition("testBean", mockBeanDefinition); | ||
|
||
assertTrue(beanFactory.containsBeanDefinition("testBean"), "Registry should contain 'testBean'"); | ||
assertFalse(beanFactory.containsBeanDefinition("nonExistentBean"), "Registry should not contain 'nonExistentBean'"); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should remove a BeanDefinition from the registry") | ||
void testRemoveBeanDefinition() { | ||
BeanDefinition mockBeanDefinition = mock(BeanDefinition.class); | ||
|
||
beanFactory.registerBeanDefinition("testBean", mockBeanDefinition); | ||
beanFactory.removeBeanDefinition("testBean"); | ||
|
||
assertFalse(beanFactory.containsBeanDefinition("testBean"), "Registry should not contain 'testBean' after removal"); | ||
} | ||
} |
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