Search in sources :

Example 1 with ArrayPrimitivesModel

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

the class ResourceModelClassesTest method testArrayPrimitivesModel.

@Test
public void testArrayPrimitivesModel() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("intArray", new int[] { 1, 2, 9, 8 });
    map.put("secondIntArray", new Integer[] { 1, 2, 9, 8 });
    ValueMap vm = new ValueMapDecorator(map);
    Resource res = mock(Resource.class);
    when(res.adaptTo(ValueMap.class)).thenReturn(vm);
    ArrayPrimitivesModel model = factory.getAdapter(res, ArrayPrimitivesModel.class);
    assertNotNull(model);
    int[] primitiveIntArray = model.getIntArray();
    assertEquals(4, primitiveIntArray.length);
    assertEquals(2, primitiveIntArray[1]);
    int[] secondPrimitiveIntArray = model.getSecondIntArray();
    assertEquals(4, secondPrimitiveIntArray.length);
    assertEquals(2, secondPrimitiveIntArray[1]);
}
Also used : ArrayPrimitivesModel(org.apache.sling.models.testmodels.classes.ArrayPrimitivesModel) 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 ArrayPrimitivesModel (org.apache.sling.models.testmodels.classes.ArrayPrimitivesModel)1 Test (org.junit.Test)1