MultiIndexDao implements IndexDao { @Override public GroupResponse group(GroupRequest groupRequest) throws InvalidSearchException { for(IndexDao dao : indices) { GroupResponse s = dao.group(groupRequest); if(s != null) { return s; } } return null; } MultiIndexDao(IndexDao... composedDao);  MultiIndexDao(Iterable<IndexDao> composedDao);  MultiIndexDao(Iterable<IndexDao> composedDao, Function<IndexDao, IndexDao> decoratorTransformation); @Override Document update(final Document update, Optional<String> index); @Override Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>> updates); @Override Map<String, FieldType> getColumnMetadata(List<String> in); @Override Document addCommentToAlert(CommentAddRemoveRequest request); @Override Document addCommentToAlert(CommentAddRemoveRequest request, Document latest); @Override Document removeCommentFromAlert(CommentAddRemoveRequest request); @Override Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest); @Override SearchResponse search(SearchRequest searchRequest); @Override GroupResponse group(GroupRequest groupRequest); @Override void init(AccessConfig config); @Override Document getLatest(final String guid, String sensorType); @Override Iterable<Document> getAllLatest(List<GetRequest> getRequests); List<IndexDao> getIndices();  }
@Test public void shouldGroup() throws Exception { GroupRequest request = new GroupRequest(); GroupResponse expected = new GroupResponse(); when(dao1.group(eq(request))).thenReturn(null); when(dao2.group(eq(request))).thenReturn(expected); GroupResponse actual = multiIndexDao.group(request); assertEquals(expected, actual); }
@Test public void shouldGroupWithNulls() throws Exception { GroupRequest request = new GroupRequest(); when(dao1.group(eq(request))).thenReturn(null); when(dao2.group(eq(request))).thenReturn(null); GroupResponse actual = multiIndexDao.group(request); assertNull(actual); }