MultiSourceAdapter implements SourceAdapter { @Override public Iterator<ObjectNode> iterator() throws SourceAdapterException { List<ObjectNode> results = new ArrayList<>(); ObjectNode resultNode = JsonNodeFactory.instance.objectNode(); for (Map.Entry<String, SourceAdapter> entry : adapterMap.entrySet()) { String alias = entry.getKey(); SourceAdapter adapter = entry.getValue(); JsonNode adapterNode = JsonMapper.valueToTree(Lists.newArrayList(adapter.iterator())); resultNode.set(alias, adapterNode); } results.add(resultNode); return results.iterator(); } @Inject  MultiSourceAdapter(
		SourceAdapterFactory adapterFactory,
		@Assisted DataSource dataSource,
		@Assisted(SourceAdapterFactory.ARGUMENT_MULTI_SOURCE) ArrayList<LinkedHashMap<String, Object>> sourceAdapters,
		MetricRegistry registry); @Override Iterator<ObjectNode> iterator();  }
@Test public void testWithOneSource() throws IOException { ArrayList<LinkedHashMap<String, Object>> adapters = createAdapterList(1); new Expectations() {{ jsonSourceAdapter.iterator(); result = JSON_ARRAY_1.iterator(); sourceAdapterFactory.createJsonSourceAdapter(dataSource, anyString); result = jsonSourceAdapter; }}; SourceAdapter multiSourceAdapter = new MultiSourceAdapter(sourceAdapterFactory, dataSource, adapters, registry); ObjectNode result = multiSourceAdapter.iterator().next(); Assert.assertFalse(result.get("sourceNr1").isNull()); Assert.assertEquals(JSON_ARRAY_1, result.get("sourceNr1")); }
@Test public void testWithTwoSources() throws IOException { ArrayList<LinkedHashMap<String, Object>> adapters = createAdapterList(2); new Expectations() {{ jsonSourceAdapter.iterator(); times = 2; returns(JSON_ARRAY_1.iterator(), JSON_ARRAY_2.iterator()); sourceAdapterFactory.createJsonSourceAdapter(dataSource, anyString); times= 2; result = jsonSourceAdapter; }}; SourceAdapter multiSourceAdapter = new MultiSourceAdapter(sourceAdapterFactory, dataSource, adapters, registry); ObjectNode result = multiSourceAdapter.iterator().next(); Assert.assertFalse(result.get("sourceNr1").isNull()); Assert.assertFalse(result.get("sourceNr2").isNull()); Assert.assertEquals(JSON_ARRAY_1, result.get("sourceNr1")); Assert.assertEquals(JSON_ARRAY_2, result.get("sourceNr2")); }