ReflectionSourceProperty implements SourceProperty { @Override public Object getValue( Object source ) { Class<?> currentClass = source.getClass(); while( currentClass != null ) { Method getter = getGetter( source, currentClass ); if( getter != null ) return getValue( getter, source ); Field field = getField( source, currentClass ); if( field != null ) return getValue( field, source ); currentClass = currentClass.getSuperclass(); } throw new MissingSourcePropertyValueException( propertyName, source.getClass() ); } ReflectionSourceProperty( String propertyName ); @Override Object getValue( Object source ); @Override Object getValue( Object source, Map<String, Object> variables ); String getExpression(); @Override String toString();  }
@Test public void testReflectionSourcePropertyCanRetrieveValueFromPrivateField() { PrivateFieldSource source = new PrivateFieldSource( "Private Value" ); assertEquals( "Private Value", rsp.getValue( source ) ); }
@Test public void testReflectionSourcePropertyCanRetrieveValueFromPublicGetGetter() { PublicGetGetterSource source = new PublicGetGetterSource( 242 ); assertEquals( 242, rsp.getValue( source ) ); }
@Test public void testReflectionSourcePropertyCanRetrieveValueFromPublicIsGetter() { PublicIsGetterSource source = new PublicIsGetterSource( true ); assertEquals( true, rsp.getValue( source ) ); }
@Test public void testReflectionSourcePropertyCanRetrieveValueFromPrivateGetGetter() { PrivateGetGetterSource source = new PrivateGetGetterSource( 123.456f ); assertEquals( 123.456f, rsp.getValue( source ) ); }
@Test public void testReflectionSourcePropertyCanRetrieveValueFromPrivateIsGetter() { PrivateIsGetterSource source = new PrivateIsGetterSource( false ); assertEquals( false, rsp.getValue( source ) ); }
@Test( expected = MissingSourcePropertyValueException.class ) public void testGetValueThrowsMissingSourcePropertyExceptionIfNoPropertyFound() { rsp.getValue( new Object( ) ); }
@Test public void testReflectionSourcePropertyCanRetrieveValueFromPublicField() { PublicFieldSource source = new PublicFieldSource(); source.value = "Public Field Value"; assertEquals( "Public Field Value", rsp.getValue( source ) ); }