### Question:
EntityManagerDaoAdapter implements Dao<Object>, Locator, Queryable, Flushable { @SuppressWarnings("unchecked") public Collection<Object> lookup(final String name, final Object ... parameters) { AssertArgument.isNotNullAndNotEmpty(name, "name"); AssertArgument.isNotNull(parameters, "parameters"); final Query emQuery = entityManager.createNamedQuery(name); for(int i = 0; i < parameters.length; i++) { emQuery.setParameter(i+1, parameters[i]); } return emQuery.getResultList(); } EntityManagerDaoAdapter(final EntityManager entityManager); void flush(); Object update(final Object entity); Object insert(final Object entity); Object delete(Object entity); @SuppressWarnings("unchecked") Collection<Object> lookup(final String name, final Object ... parameters); @SuppressWarnings("unchecked") Collection<Object> lookup(final String name, final Map<String, ?> parameters); @SuppressWarnings("unchecked") Collection<Object> lookupByQuery(final String query, final Object ... parameters); @SuppressWarnings("unchecked") Collection<Object> lookupByQuery(final String query, final Map<String, ?> parameters); EntityManager getEntityManager();  }### Answer:
@Test( groups = "unit" ) public void test_lookup_map_parameters() { List<?> listResult = Collections.emptyList(); stub(entityManager.createNamedQuery(anyString())).toReturn(query); stub(query.getResultList()).toReturn(listResult); Map<String, Object> params = new HashMap<String, Object>(); params.put("key1", "value1"); params.put("key2", "value2"); Collection<Object> result = adapter.lookup("name", params); assertSame(listResult, result); verify(entityManager).createNamedQuery(eq("name")); verify(query).setParameter(eq("key1"), eq("value1")); verify(query).setParameter(eq("key2"), eq("value2")); verify(query).getResultList(); }
@Test( groups = "unit" ) public void test_lookup_array_parameters() { List<?> listResult = Collections.emptyList(); stub(entityManager.createNamedQuery(anyString())).toReturn(query); stub(query.getResultList()).toReturn(listResult); Object[] params = new Object[2]; params[0] = "value1"; params[1] = "value2"; Collection<Object> result = adapter.lookup("name", params); assertSame(listResult, result); verify(entityManager).createNamedQuery(eq("name")); verify(query).setParameter(eq(1), eq("value1")); verify(query).setParameter(eq(2), eq("value2")); verify(query).getResultList(); }