package polyglot.grpc;

import static org.mockito.Mockito.verify;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import io.grpc.stub.StreamObserver;


/** Unit tests for {@link CompositeStreamObserver}. */
public class CompositeStreamObserverTest {
  @Rule public MockitoRule mockitoJunitRule = MockitoJUnit.rule();
  @Mock private StreamObserver<SomeType> mockFirstObserver;
  @Mock private StreamObserver<SomeType> mockSecondObserver;

  private CompositeStreamObserver<SomeType> compositeObserver;

  @Before
  public void setUp() {
    compositeObserver = CompositeStreamObserver.of(mockFirstObserver, mockSecondObserver);
  }

  @Test
  public void callsOnNext() {
    SomeType value = new SomeType();
    compositeObserver.onNext(value);
    verify(mockFirstObserver).onNext(value);
    verify(mockSecondObserver).onNext(value);
  }

  @Test
  public void callsOnComplete() {
    compositeObserver.onCompleted();
    verify(mockFirstObserver).onCompleted();
    verify(mockSecondObserver).onCompleted();
  }

  @Test
  public void forwardsErrors() {
    Throwable t = new Exception();
    compositeObserver.onError(t);
    verify(mockFirstObserver).onError(t);
    verify(mockSecondObserver).onError(t);
  }

  private static class SomeType {
  }
}

@@ -17,16 +17,59 @@
 .grpc;%0A%0A
+import static org.mockito.Mockito.doThrow;%0A
 import s
@@ -996,32 +996,332 @@
 xt(value);%0A  %7D%0A%0A
+  @Test%0A  public void callOthersEvenIfOneErrorsOut() %7B%0A    SomeType value = new SomeType();%0A    doThrow(new RuntimeException()).when(mockFirstObserver).onNext(value);%0A    compositeObserver.onNext(value);%0A    verify(mockFirstObserver).onNext(value);%0A    verify(mockSecondObserver).onNext(value);%0A  %7D%0A%0A
   @Test%0A  public

Add a better test for the composite stream observer.