Code example for Session

Methods: getNamedQuery

0
 
        // STUB 
 
        List<?> listResult = Collections.emptyList();
 
        when(session.getNamedQuery(anyString())).thenReturn(query);
        when(query.list()).thenReturn(listResult);
 
        // EXECUTE 
 
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("key1", "value1"); 
        params.put("key2", "value2"); 
 
        Object result = adapter.lookup("name", params);
 
        // VERIFY 
 
        assertSame(listResult, result);
 
        verify(session).getNamedQuery(eq("name"));
 
        verify(query).setParameter(eq("key1"), eq("value1"));
        verify(query).setParameter(eq("key2"), eq("value2"));
        verify(query).list();