ServerCalls { public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncServerStreamingCall( final ServerStreamingMethod<ReqT, RespT> method) { return asyncUnaryRequestCall(method); } private  ServerCalls(); static ServerCallHandler<ReqT, RespT> asyncUnaryCall(
      final UnaryMethod<ReqT, RespT> method); static ServerCallHandler<ReqT, RespT> asyncServerStreamingCall(
      final ServerStreamingMethod<ReqT, RespT> method); static ServerCallHandler<ReqT, RespT> asyncClientStreamingCall(
      final ClientStreamingMethod<ReqT, RespT> method); static ServerCallHandler<ReqT, RespT> asyncBidiStreamingCall(
      final BidiStreamingMethod<ReqT, RespT> method); static void asyncUnimplementedUnaryCall(MethodDescriptor<?, ?> methodDescriptor,
      StreamObserver<?> responseObserver); static StreamObserver<T> asyncUnimplementedStreamingCall(
      MethodDescriptor<?, ?> methodDescriptor, StreamObserver<?> responseObserver);  }
@Test public void onReadyHandlerCalledForUnaryRequest() throws Exception { final AtomicInteger onReadyCalled = new AtomicInteger(); final AtomicReference<ServerCallStreamObserver<Integer>> callObserver = new AtomicReference<ServerCallStreamObserver<Integer>>(); ServerCallHandler<Integer, Integer> callHandler = ServerCalls.asyncServerStreamingCall( new ServerCalls.ServerStreamingMethod<Integer, Integer>() { @Override public void invoke(Integer req, StreamObserver<Integer> responseObserver) { ServerCallStreamObserver<Integer> serverCallObserver = (ServerCallStreamObserver<Integer>) responseObserver; serverCallObserver.setOnReadyHandler(new Runnable() { @Override public void run() { onReadyCalled.incrementAndGet(); } }); } }); ServerCall.Listener<Integer> callListener = callHandler.startCall(STREAMING_METHOD, serverCall, new Metadata()); Mockito.when(serverCall.isReady()).thenReturn(true).thenReturn(false); Mockito.when(serverCall.isCancelled()).thenReturn(false).thenReturn(true); callListener.onReady(); assertEquals(0, onReadyCalled.get()); callListener.onMessage(1); assertEquals(0, onReadyCalled.get()); callListener.onHalfClose(); assertEquals(1, onReadyCalled.get()); callListener.onReady(); assertEquals(2, onReadyCalled.get()); }