Search in sources :

Example 1 with ArrayWrappersModel

use of org.apache.sling.models.testmodels.classes.ArrayWrappersModel in project sling by apache.

the class ResourceModelClassesTest method testArrayWrappersModel.

@Test
public void testArrayWrappersModel() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("intArray", new Integer[] { 1, 2, 9, 8 });
    map.put("secondIntArray", new int[] { 1, 2, 9, 8 });
    ValueMap vm = new ValueMapDecorator(map);
    Resource res = mock(Resource.class);
    when(res.adaptTo(ValueMap.class)).thenReturn(vm);
    ArrayWrappersModel model = factory.getAdapter(res, ArrayWrappersModel.class);
    assertNotNull(model);
    Integer[] intArray = model.getIntArray();
    assertEquals(4, intArray.length);
    assertEquals(new Integer(2), intArray[1]);
    Integer[] secondIntArray = model.getSecondIntArray();
    assertEquals(4, secondIntArray.length);
    assertEquals(new Integer(2), secondIntArray[1]);
}
Also used : ArrayWrappersModel(org.apache.sling.models.testmodels.classes.ArrayWrappersModel) HashMap(java.util.HashMap) ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Resource (org.apache.sling.api.resource.Resource)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)1 ArrayWrappersModel (org.apache.sling.models.testmodels.classes.ArrayWrappersModel)1 Test (org.junit.Test)1