Search in sources :

Example 1 with PropertyValue

use of groovy.lang.PropertyValue in project groovy-core by groovy.

the class Inspector method getPropertyInfo.

/**
     * Get info about Properties (Java and Groovy alike).
     *
     * @return Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants
     */
public Object[] getPropertyInfo() {
    List props = DefaultGroovyMethods.getMetaPropertyValues(objectUnderInspection);
    Object[] result = new Object[props.size()];
    int i = 0;
    for (Iterator iter = props.iterator(); iter.hasNext(); i++) {
        PropertyValue pv = (PropertyValue) iter.next();
        result[i] = fieldInfo(pv);
    }
    return result;
}
Also used : PropertyValue(groovy.lang.PropertyValue) GroovyObject(groovy.lang.GroovyObject)

Example 2 with PropertyValue

use of groovy.lang.PropertyValue in project groovy-core by groovy.

the class InspectorTest method testInspectUninspectableProperty.

// TODO: if our code can never access inspect in this way, it would be better
// to move this to a boundary class and then we wouldn't need this test
public void testInspectUninspectableProperty() {
    Object dummyInstance = new Object();
    Inspector inspector = getTestableInspector(dummyInstance);
    Class[] paramTypes = { Object.class, MetaProperty.class };
    Object[] params = { null, null };
    Mock mock = mock(PropertyValue.class, paramTypes, params);
    mock.expects(once()).method("getType");
    mock.expects(once()).method("getName");
    mock.expects(once()).method("getValue").will(throwException(new RuntimeException()));
    PropertyValue propertyValue = (PropertyValue) mock.proxy();
    String[] result = inspector.fieldInfo(propertyValue);
    assertEquals(Inspector.NOT_APPLICABLE, result[Inspector.MEMBER_VALUE_IDX]);
}
Also used : PropertyValue(groovy.lang.PropertyValue) Mock(org.jmock.Mock)

Example 3 with PropertyValue

use of groovy.lang.PropertyValue in project groovy by apache.

the class Inspector method getPropertyInfo.

/**
     * Get info about Properties (Java and Groovy alike).
     *
     * @return Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants
     */
public Object[] getPropertyInfo() {
    List props = DefaultGroovyMethods.getMetaPropertyValues(objectUnderInspection);
    Object[] result = new Object[props.size()];
    int i = 0;
    for (Iterator iter = props.iterator(); iter.hasNext(); i++) {
        PropertyValue pv = (PropertyValue) iter.next();
        result[i] = fieldInfo(pv);
    }
    return result;
}
Also used : PropertyValue(groovy.lang.PropertyValue) GroovyObject(groovy.lang.GroovyObject)

Example 4 with PropertyValue

use of groovy.lang.PropertyValue in project groovy by apache.

the class InspectorTest method testInspectUninspectableProperty.

// TODO: if our code can never access inspect in this way, it would be better
// to move this to a boundary class and then we wouldn't need this test
public void testInspectUninspectableProperty() {
    Object dummyInstance = new Object();
    Inspector inspector = getTestableInspector(dummyInstance);
    Class[] paramTypes = { Object.class, MetaProperty.class };
    Object[] params = { null, null };
    Mock mock = mock(PropertyValue.class, paramTypes, params);
    mock.expects(once()).method("getType");
    mock.expects(once()).method("getName");
    mock.expects(once()).method("getValue").will(throwException(new RuntimeException()));
    PropertyValue propertyValue = (PropertyValue) mock.proxy();
    String[] result = inspector.fieldInfo(propertyValue);
    assertEquals(Inspector.NOT_APPLICABLE, result[Inspector.MEMBER_VALUE_IDX]);
}
Also used : PropertyValue(groovy.lang.PropertyValue) Mock(org.jmock.Mock)

Aggregations

PropertyValue (groovy.lang.PropertyValue)4 GroovyObject (groovy.lang.GroovyObject)2 Mock (org.jmock.Mock)2