package com.github.ferstl.streams;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static java.lang.Thread.currentThread;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;


public class ParallelStreamSupportTest {

  private ForkJoinPool workerPool;

  private Stream<String> delegate;
  private ParallelStreamSupport<String> parallelStreamSupport;

  @Before
  @SuppressWarnings("unchecked")
  public void before() {
    // Precondition for all tests
    assertFalse("This test must not run in a ForkJoinPool", currentThread() instanceof ForkJoinWorkerThread);

    this.workerPool = new ForkJoinPool(1);
    this.delegate = mock(Stream.class);
    this.parallelStreamSupport = new ParallelStreamSupport<>(this.delegate, this.workerPool);
  }

  @After
  public void after() throws InterruptedException {
    this.workerPool.shutdown();
    this.workerPool.awaitTermination(1, TimeUnit.SECONDS);
  }


  @Test
  public void sequential() {
    Stream<String> stream = this.parallelStreamSupport.sequential();

    verify(this.delegate).sequential();
    assertSame(this.parallelStreamSupport, stream);
  }
}

@@ -29,16 +29,45 @@
 reams;%0A%0A
+import java.util.Comparator;%0A
 import j
@@ -100,16 +100,16 @@
 inPool;%0A
-
 import j
@@ -188,16 +188,89 @@
 meUnit;%0A
+import java.util.function.Consumer;%0Aimport java.util.function.Predicate;%0A
 import j
@@ -1415,24 +1415,24 @@
 uential();%0A%0A
-
     verify(t
@@ -1514,11 +1514,2106 @@
 am);%0A  %7D
+%0A%0A  @Test%0A  public void parallel() %7B%0A    Stream%3CString%3E stream = this.parallelStreamSupport.parallel();%0A%0A    verify(this.delegate).parallel();%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void unordered() %7B%0A    Stream%3CString%3E stream = this.parallelStreamSupport.unordered();%0A%0A    verify(this.delegate).unordered();%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void onClose() %7B%0A    Runnable r = () -%3E %7B%7D;%0A    Stream%3CString%3E stream = this.parallelStreamSupport.onClose(r);%0A%0A    verify(this.delegate).onClose(r);%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void filter() %7B%0A    Predicate%3CString%3E p = s -%3E true;%0A    Stream%3CString%3E stream = this.parallelStreamSupport.filter(p);%0A%0A    verify(this.delegate).filter(p);%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void distinct() %7B%0A    Stream%3CString%3E stream = this.parallelStreamSupport.distinct();%0A%0A    verify(this.delegate).distinct();%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void sorted() %7B%0A    Stream%3CString%3E stream = this.parallelStreamSupport.sorted();%0A%0A    verify(this.delegate).sorted();%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void sortedWithComparator() %7B%0A    Comparator%3CString%3E c = (s1, s2) -%3E 0;%0A    Stream%3CString%3E stream = this.parallelStreamSupport.sorted(c);%0A%0A    verify(this.delegate).sorted(c);%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void peek() %7B%0A    Consumer%3CString%3E c = s -%3E %7B%7D;%0A    Stream%3CString%3E stream = this.parallelStreamSupport.peek(c);%0A%0A    verify(this.delegate).peek(c);%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void limit() %7B%0A    Stream%3CString%3E stream = this.parallelStreamSupport.limit(5);%0A%0A    verify(this.delegate).limit(5);%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D%0A%0A  @Test%0A  public void skip() %7B%0A    Stream%3CString%3E stream = this.parallelStreamSupport.skip(5);%0A%0A    verify(this.delegate).skip(5);%0A    assertSame(this.parallelStreamSupport, stream);%0A  %7D
 %0A%7D%0A

Add tests for methods returning the same stream