|
31 | 31 | import org.springframework.core.annotation.AnnotationAttributes; |
32 | 32 |
|
33 | 33 | import java.beans.PropertyDescriptor; |
| 34 | +import java.util.concurrent.TimeUnit; |
34 | 35 |
|
35 | 36 | import static io.microsphere.spring.boot.context.properties.bind.ConfigurationPropertiesBeanContext.getInstance; |
| 37 | +import static io.microsphere.spring.boot.context.properties.bind.ConfigurationPropertiesBeanContext.isCandidateClass; |
36 | 38 | import static io.microsphere.spring.boot.context.properties.bind.ConfigurationPropertiesBeanContext.isCandidateProperty; |
37 | 39 | import static io.microsphere.spring.core.annotation.AnnotationUtils.getAnnotationAttributes; |
38 | 40 | import static org.junit.jupiter.api.Assertions.assertEquals; |
@@ -144,11 +146,33 @@ void testGetInstance() { |
144 | 146 |
|
145 | 147 | @Test |
146 | 148 | void testIsCandidateProperty() { |
| 149 | + assertFalse(isCandidateProperty(null)); |
147 | 150 | PropertyDescriptor descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "name"); |
148 | | - assertTrue(isCandidateProperty(descriptor)); |
| 151 | + assertFalse(isCandidateProperty(descriptor)); |
| 152 | + |
| 153 | + descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "not-found"); |
| 154 | + assertFalse(isCandidateProperty(descriptor)); |
149 | 155 |
|
150 | 156 | descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "class"); |
151 | 157 | assertFalse(isCandidateProperty(descriptor)); |
| 158 | + |
| 159 | + descriptor = getPropertyDescriptor(ServerProperties.class, "port"); |
| 160 | + assertTrue(isCandidateProperty(descriptor)); |
| 161 | + } |
| 162 | + |
| 163 | + @Test |
| 164 | + void testIsCandidateClass() { |
| 165 | + // null |
| 166 | + assertFalse(isCandidateClass(null)); |
| 167 | + // primitive type and wrapper type are not candidate class |
| 168 | + assertFalse(isCandidateClass(int.class)); |
| 169 | + assertFalse(isCandidateClass(Integer.class)); |
| 170 | + // enumeration type |
| 171 | + assertFalse(isCandidateClass(TimeUnit.class)); |
| 172 | + // String is candidate class,but is under java.lang package. |
| 173 | + assertFalse(isCandidateClass(String.class)); |
| 174 | + // current class |
| 175 | + assertTrue(isCandidateClass(getClass())); |
152 | 176 | } |
153 | 177 |
|
154 | 178 | public void setName(String name) { |
|
0 commit comments