MultiReference implements Reference<E> { public Reference<E> narrow(Class<?> type) throws BindingException { List<Reference<E>> resulting = new ArrayList<Reference<E>>(); for (Reference<E> reference :references) { Reference<E> result = reference.narrow(type); if (result != null) { resulting.add(result); } } if (resulting.size() == 0) { return null; } else { return new MultiReference<E>(resulting.toArray(REFERENCE_ARRAY_TYPE)); } } MultiReference(Reference<E>... references); ReferenceContext<E> getReferenceContext(); Object resolve(E context); Reference<E> selectItem(String index); Reference<E> selectItem(Expression<Integer, E> index); Reference<E> selectAttribute(String name); void document(Document target); boolean isAssignableTo(Class<?> type); Class<?> getType(); Reference<E> narrow(Class<?> type); boolean isBasedOn(ReferenceContext<E> context); Reference<E> rescope(ReferenceContext<E> eReferenceContext);  }
@Test public void testNarrow() { StringBuilder builder = new StringBuilder(); Document document = new StringBuilderDocument(builder); String propertyName = "pi"; expect(reference1.narrow(String.class)).andReturn(reference1); expect(reference2.narrow(String.class)).andReturn(reference2); expect(reference1.getType()).andReturn(String.class).times(2); expect(reference2.getType()).andReturn(String.class).times(2); expect(reference1.getReferenceContext()).andReturn(context).times(2); expect(reference2.getReferenceContext()).andReturn(context).times(2); replay(reference1, reference2, context); MultiReference multi = new MultiReference(reference1, reference2); multi.narrow(String.class); verify(reference1, reference2, context); }