Search in sources :

Example 1 with IValueGenerator

use of org.eclipse.nebula.widgets.nattable.dataset.generator.IValueGenerator in project nebula.widgets.nattable by eclipse.

the class DataValueGeneratorTest method testClassAnnotationDataCanBeAccessed.

// TODO The following test probably has a race condition - test
// non-deterministic
@Test
public void testClassAnnotationDataCanBeAccessed() throws Exception {
    final Random random = new Random();
    final PricingDataBean bean = new PricingDataBean();
    for (Field field : bean.getClass().getDeclaredFields()) {
        if (field.isAnnotationPresent(DataValueGenerator.class)) {
            field.setAccessible(true);
            try {
                Class<? extends IValueGenerator> generatorClass = field.getAnnotation(DataValueGenerator.class).value();
                IValueGenerator generator = generatorClass.newInstance();
                Object newValue = generator.newValue(random);
                // System.out.println("newValue: "+newValue + "\t" +
                // generator.getClass().getName());
                assertNotNull(newValue);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) DataValueGenerator(org.eclipse.nebula.widgets.nattable.dataset.generator.DataValueGenerator) Random(java.util.Random) IValueGenerator(org.eclipse.nebula.widgets.nattable.dataset.generator.IValueGenerator) PricingDataBean(org.eclipse.nebula.widgets.nattable.dataset.pricing.PricingDataBean) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 Random (java.util.Random)1 DataValueGenerator (org.eclipse.nebula.widgets.nattable.dataset.generator.DataValueGenerator)1 IValueGenerator (org.eclipse.nebula.widgets.nattable.dataset.generator.IValueGenerator)1 PricingDataBean (org.eclipse.nebula.widgets.nattable.dataset.pricing.PricingDataBean)1 Test (org.junit.Test)1