### Question:
Sources { public static <T> Source<T> merge( List<? extends Source<? extends T>> sortedSources, Comparator<? super T> comparator) { if (sortedSources.isEmpty()) { return empty(); } else if (sortedSources.size() == 1) { @SuppressWarnings("unchecked") Source<T> source = (Source<T>) sortedSources.get(0); return source; } return new HeapSource<>(sortedSources, comparator); } private  Sources(); static Source<T> empty(); @SafeVarargs static Source<T> wrap(T... values); static Source<T> wrap(Iterator<? extends T> iterator); static Source<T> concat(List<? extends Source<? extends T>> sources); static Source<T> merge(
            List<? extends Source<? extends T>> sortedSources,
            Comparator<? super T> comparator);  }### Answer:
@Test public void merge() { List<Source<IntBuf>> cursors = new ArrayList<>(); cursors.add(Sources.wrap(array(1, 4, 7))); cursors.add(Sources.wrap(array(2, 5, 8))); cursors.add(Sources.wrap(array(3, 6, 9))); check(Sources.merge(cursors, IntBuf.COMPARATOR), 1, 2, 3, 4, 5, 6, 7, 8, 9); }
@Test public void merge_empty() { List<Source<IntBuf>> cursors = new ArrayList<>(); check(Sources.merge(cursors, IntBuf.COMPARATOR)); }
@Test public void merge_large() throws Exception { int base = 1000000; List<Source<IntBuf>> cursors = new ArrayList<>(); cursors.add(new IntSource(random(new Random(6502 + 0), base * 3))); cursors.add(new IntSource(random(new Random(6502 + 1), base * 3))); cursors.add(new IntSource(random(new Random(6502 + 2), base * 4))); int last = -1; int count = 0; try (Source<IntBuf> c = Sources.merge(cursors, IntBuf.COMPARATOR)) { while (c.next()) { int next = c.get().value; assertTrue(last <= next); last = next; count++; } } assertThat(count, is(base * 10)); }
@Test public void merge_many() throws Exception { int numSources = 1000; int base = 1000; List<Source<IntBuf>> cursors = new ArrayList<>(); for (int i = 0; i < numSources; i++) { cursors.add(new IntSource(random(new Random(6502 + i), base))); } int last = -1; int count = 0; try (Source<IntBuf> c = Sources.merge(cursors, IntBuf.COMPARATOR)) { while (c.next()) { int next = c.get().value; assertTrue(last <= next); last = next; count++; } } assertThat(count, is(base * numSources)); }