Search in sources :

Example 1 with ListModel

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

the class ResourceModelClassesTest method testListModel.

@Test
public void testListModel() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("intList", new Integer[] { 1, 2, 9, 8 });
    map.put("stringList", new String[] { "hello", "world" });
    ValueMap vm = new ValueMapDecorator(map);
    Resource res = mock(Resource.class);
    when(res.adaptTo(ValueMap.class)).thenReturn(vm);
    ListModel model = factory.getAdapter(res, ListModel.class);
    assertNotNull(model);
    assertEquals(4, model.getIntList().size());
    assertEquals(new Integer(2), model.getIntList().get(1));
    assertEquals(2, model.getStringList().size());
    assertEquals("hello", model.getStringList().get(0));
}
Also used : HashMap(java.util.HashMap) ValueMap(org.apache.sling.api.resource.ValueMap) ListModel(org.apache.sling.models.testmodels.classes.ListModel) 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 ListModel (org.apache.sling.models.testmodels.classes.ListModel)1 Test (org.junit.Test)1