@Test
public void getBeanProperty() throws Exception {

    InternetPerson person = new InternetPerson();
    
    // assert default properties
    Assert.assertNull(person.getFirstName());
    Assert.assertNull(person.getLastName());
    Assert.assertEquals(-1, person.getId());
    // use utility class to get the "bean" property
    BeanProperty beanProperty = BeanUtil.findBeanProperty(InternetPerson.class, "firstName", true);
    Assert.assertEquals(Person.class.getDeclaredField("firstName"), beanProperty.getField());
    //Assert.assertEquals(Person.class.getDeclaredMethod("getFirstName"), beanProperty.getGetMethod());
    //Assert.assertEquals(Person.class.getDeclaredMethod("setFirstName", String.class), beanProperty.getSetMethod());
    Assert.assertEquals(String.class, beanProperty.getType());
    Assert.assertEquals("firstName", beanProperty.getName());
    // use getter/setter (should use underlying getter and setter methods)
    beanProperty.set(person, "Joe");
    Assert.assertEquals("Joe", beanProperty.get(person));
    Assert.assertEquals("Joe", person.getFirstName());
    // now let's test the usage of underlying field for all access
    BeanProperty beanProperty2 = BeanUtil.findBeanProperty(InternetPerson.class, "extraInfo", true);
    Assert.assertEquals(null, beanProperty2.get(person));
    beanProperty2.set(person, "MoreInfoHere");
    Assert.assertEquals("MoreInfoHere", beanProperty2.get(person));
    // test properties that throw exceptions
    ServerConfig config = new ServerConfig();
    BeanProperty beanProperty3 = BeanUtil.findBeanProperty(config.getClass(), "port", true);
    
    // this an int property, let's try a string
    try {
        beanProperty3.set(config, "80");
        Assert.fail("String arg should have thrown exception");
    } catch (IllegalArgumentException e) {
        // this is expected behavior
    }
    try {
        beanProperty3.set(config, -80);
        Assert.fail("negative port arg should have thrown exception");
    } catch (InvocationTargetException e) {
        Assert.assertEquals(ServerConfigException.class, e.getCause().getClass());
    }
    // the "set" method for port throws an exception if <= 0
    beanProperty3.set(config, 80);
    Assert.assertEquals(80, beanProperty3.get(config));
}