Search in sources :

Example 1 with ArrayClassMeta

use of org.simpleflatmapper.reflect.meta.ArrayClassMeta in project SimpleFlatMapper by arnaudroger.

the class ListClassMetaTest method hasOneInstantiatorDefinitionWithEmptyConstructorOnImpl.

private void hasOneInstantiatorDefinitionWithEmptyConstructorOnImpl(ClassMeta<?> classMeta, Class<?> impl) throws NoSuchMethodException {
    assertTrue(classMeta instanceof ArrayClassMeta);
    final List<InstantiatorDefinition> instantiatorDefinitions = classMeta.getInstantiatorDefinitions();
    assertEquals(1, instantiatorDefinitions.size());
    final ExecutableInstantiatorDefinition instantiatorDefinition = (ExecutableInstantiatorDefinition) instantiatorDefinitions.get(0);
    assertEquals(0, instantiatorDefinition.getParameters().length);
    assertEquals(impl.getDeclaredConstructor(), instantiatorDefinition.getExecutable());
}
Also used : ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) InstantiatorDefinition(org.simpleflatmapper.reflect.InstantiatorDefinition) ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) ArrayClassMeta(org.simpleflatmapper.reflect.meta.ArrayClassMeta)

Example 2 with ArrayClassMeta

use of org.simpleflatmapper.reflect.meta.ArrayClassMeta in project SimpleFlatMapper by arnaudroger.

the class ArrayClassMetaTest method testSet.

private Object testSet(TypeReference<?> typeReference) throws Exception {
    ClassMeta<?> classMeta = ReflectionService.newInstance().getClassMeta(typeReference.getType());
    assertTrue(classMeta instanceof ArrayClassMeta);
    PropertyMeta p = findProperty(classMeta);
    Set<String> list = (Set<String>) instantiate(classMeta);
    p.getSetter().set(list, "aaa");
    assertEquals(null, p.getGetter().get(list));
    assertEquals("aaa", list.iterator().next());
    return list;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ArrayClassMeta(org.simpleflatmapper.reflect.meta.ArrayClassMeta) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta)

Example 3 with ArrayClassMeta

use of org.simpleflatmapper.reflect.meta.ArrayClassMeta in project SimpleFlatMapper by arnaudroger.

the class ArrayClassMetaTest method testArrayObject.

@Test
public void testArrayObject() throws Exception {
    ClassMeta<?> classMeta = ReflectionService.newInstance().getClassMeta(Object[].class);
    assertTrue(classMeta instanceof ArrayClassMeta);
    PropertyMeta p = classMeta.newPropertyFinder(new Predicate() {

        @Override
        public boolean test(Object propertyMeta) {
            return true;
        }
    }).findProperty(DefaultPropertyNameMatcher.of("3"), new Object[0]);
    Object[] array = new Object[10];
    p.getSetter().set(array, "aaa");
    assertEquals("aaa", p.getGetter().get(array));
    assertEquals("aaa", array[3]);
}
Also used : ArrayClassMeta(org.simpleflatmapper.reflect.meta.ArrayClassMeta) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) Predicate(org.simpleflatmapper.util.Predicate) Test(org.junit.Test)

Example 4 with ArrayClassMeta

use of org.simpleflatmapper.reflect.meta.ArrayClassMeta in project SimpleFlatMapper by arnaudroger.

the class ArrayClassMetaTest method testArrayPrimitive.

private void testArrayPrimitive(Class<?> component, Object value) throws Exception {
    assertTrue(component.isPrimitive());
    Object array = Array.newInstance(component, 10);
    ClassMeta<?> classMeta = ReflectionService.newInstance().getClassMeta(array.getClass());
    assertTrue(classMeta instanceof ArrayClassMeta);
    PropertyMeta p = classMeta.newPropertyFinder(new Predicate() {

        @Override
        public boolean test(Object propertyMeta) {
            return true;
        }
    }).findProperty(DefaultPropertyNameMatcher.of("3"), new Object[0]);
    p.getSetter().set(array, value);
    assertEquals(value, p.getGetter().get(array));
    assertEquals(value, Array.get(array, 3));
}
Also used : ArrayClassMeta(org.simpleflatmapper.reflect.meta.ArrayClassMeta) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) Predicate(org.simpleflatmapper.util.Predicate)

Example 5 with ArrayClassMeta

use of org.simpleflatmapper.reflect.meta.ArrayClassMeta in project SimpleFlatMapper by arnaudroger.

the class ArrayClassMetaTest method testGetterSetterOnList.

private Object testGetterSetterOnList(TypeReference<?> typeReference) throws Exception {
    ClassMeta<?> classMeta = ReflectionService.newInstance().getClassMeta(typeReference.getType());
    assertTrue(classMeta instanceof ArrayClassMeta);
    PropertyMeta p = findProperty(classMeta);
    Object list = instantiate(classMeta);
    p.getSetter().set(list, "aaa");
    assertEquals("aaa", p.getGetter().get(list));
    return list;
}
Also used : ArrayClassMeta(org.simpleflatmapper.reflect.meta.ArrayClassMeta) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta)

Aggregations

ArrayClassMeta (org.simpleflatmapper.reflect.meta.ArrayClassMeta)5 PropertyMeta (org.simpleflatmapper.reflect.meta.PropertyMeta)4 Predicate (org.simpleflatmapper.util.Predicate)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1 InstantiatorDefinition (org.simpleflatmapper.reflect.InstantiatorDefinition)1 ExecutableInstantiatorDefinition (org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition)1