Example usage for org.apache.commons.lang.reflect FieldUtils getField

List of usage examples for org.apache.commons.lang.reflect FieldUtils getField

Introduction

In this page you can find the example usage for org.apache.commons.lang.reflect FieldUtils getField.

Prototype

public static Field getField(final Class cls, String fieldName, boolean forceAccess) 

Source Link

Document

Gets an accessible Field by name breaking scope if requested.

Usage

From source file:org.openhab.binding.weather.internal.utils.PropertyUtils.java

/**
 * Returns the type name of the property of the instance.
 *///w  w w. j av  a  2  s. com
public static String getPropertyTypeName(Object instance, String property) throws IllegalAccessException {
    Object object = getNestedObject(instance, property);
    Field field = FieldUtils.getField(object.getClass(), PropertyResolver.last(property), true);
    return field.getType().getCanonicalName();
}

From source file:org.pentaho.di.trans.steps.googleanalytics.GaInputStepTest.java

@Test
public void getNextDataEntry_WithPaging() throws Exception {
    final int recordsCount = 30;

    final String stepName = "GaInputStepTest";

    StepMeta stepMeta = new StepMeta(stepName, stepName, new GaInputStepMeta());

    Trans trans = mock(Trans.class);

    TransMeta transMeta = mock(TransMeta.class);
    when(transMeta.findStep(stepName)).thenReturn(stepMeta);

    GaInputStepData data = new GaInputStepData();

    GaInputStep step = new GaInputStep(stepMeta, data, 0, transMeta, trans);

    FieldUtils.writeField(FieldUtils.getField(GaInputStep.class, "data", true), step, data, true);

    Analytics.Data.Ga.Get mockQuery = prepareMockQuery(recordsCount);
    step = spy(step);/* w ww. ja  va2 s.co m*/
    doReturn(mockQuery).when(step).getQuery(any(Analytics.class));

    for (int i = 0; i < recordsCount; i++) {
        List<String> next = step.getNextDataEntry();
        assertEquals(Integer.toString(i + 1), next.get(0));
    }
    assertNull(step.getNextDataEntry());
}