forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadJavaBeanPropertiesTest.java
More file actions
25 lines (21 loc) · 989 Bytes
/
ReadJavaBeanPropertiesTest.java
File metadata and controls
25 lines (21 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.examplehub.basics.oop;
import static org.junit.jupiter.api.Assertions.*;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import org.junit.jupiter.api.Test;
class ReadJavaBeanPropertiesTest {
@Test
void test() throws IntrospectionException {
BeanInfo beanInfo = Introspector.getBeanInfo(MyBean.class);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
assertEquals(3, propertyDescriptors.length);
assertEquals("age", propertyDescriptors[0].getName());
assertEquals("getAge", propertyDescriptors[0].getReadMethod().getName());
assertEquals("setAge", propertyDescriptors[0].getWriteMethod().getName());
assertEquals("name", propertyDescriptors[2].getName());
assertEquals("getName", propertyDescriptors[2].getReadMethod().getName());
assertEquals("setName", propertyDescriptors[2].getWriteMethod().getName());
}
}