/*
 * Copyright 2017, gRPC Authors All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.grpc.testing;

import io.grpc.ExperimentalApi;
import io.grpc.MethodDescriptor;
import io.grpc.MethodDescriptor.MethodType;
import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * A collection of method descriptor constructors useful for tests.  These are useful if you need
 * a descriptor, but don't really care how it works.
 *
 * @since 1.1.0
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
public final class TestMethodDescriptors {
  private TestMethodDescriptors() {}

  /**
   * Creates a new method descriptor that always creates zero length messages, and always parses to
   * null objects.
   *
   * @since 1.1.0
   */
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
  public static MethodDescriptor<Void, Void> voidMethod() {
    return MethodDescriptor.<Void, Void>newBuilder()
        .setType(MethodType.UNARY)
        .setFullMethodName(MethodDescriptor.generateFullMethodName("service_foo", "method_bar"))
        .setRequestMarshaller(TestMethodDescriptors.voidMarshaller())
        .setResponseMarshaller(TestMethodDescriptors.voidMarshaller())
        .build();
  }

  /**
   * Creates a new method descriptor that always creates zero length messages, and always parses to
   * null objects.
   *
   * @deprecated Prefer to use {@link #voidMethod()} instead or use one MethodDescriptor from {@code
   *             io.grpc.testing.protobuf.SimpleServiceGrpc} or from other generated classes.
   * @since 1.1.0
   */
  @Deprecated
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
  public static <ReqT, RespT> MethodDescriptor<ReqT, RespT> noopMethod() {
    return noopMethod("service_foo", "method_bar");
  }

  @Deprecated
  private static <ReqT, RespT> MethodDescriptor<ReqT, RespT> noopMethod(
      String serviceName, String methodName) {
    return MethodDescriptor.<ReqT, RespT>newBuilder()
        .setType(MethodType.UNARY)
        .setFullMethodName(MethodDescriptor.generateFullMethodName(serviceName, methodName))
        .setRequestMarshaller(TestMethodDescriptors.<ReqT>noopMarshaller())
        .setResponseMarshaller(TestMethodDescriptors.<RespT>noopMarshaller())
        .build();
  }

  /**
   * Creates a new marshaller that does nothing.
   *
   * @since 1.1.0
   */
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
  public static MethodDescriptor.Marshaller<Void> voidMarshaller() {
    return new NoopMarshaller<Void>();
  }

  /**
   * Creates a new marshaller that does nothing.
   *
   * @deprecated Use {@link #voidMarshaller()} instead or implement/mock one
   * @since 1.1.0
   */
  @Deprecated
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
  public static <T> MethodDescriptor.Marshaller<T> noopMarshaller() {
    return new NoopMarshaller<T>();
  }

  private static final class NoopMarshaller<T> implements MethodDescriptor.Marshaller<T> {
    @Override
    public InputStream stream(T value) {
      return new ByteArrayInputStream(new byte[]{});
    }

    @Override
    public T parse(InputStream stream) {
      return null;
    }
  }
}

@@ -1799,1648 +1799,232 @@
 ew m
-ethod descriptor that always creates zero length messages, and always parses to%0A   * null objects.%0A   *%0A   * @deprecated Prefer to use %7B@link #voidMethod()%7D instead or use one MethodDescriptor from %7B@code%0A   *             io.grpc.testing.protobuf.SimpleServiceGrpc%7D or from other generated classes.%0A   * @since 1.1.0%0A   */%0A  @Deprecated%0A  @ExperimentalApi(%22https://github.com/grpc/grpc-java/issues/2600%22)%0A  public static %3CReqT, RespT%3E MethodDescriptor%3CReqT, RespT%3E noopMethod() %7B%0A    return noopMethod(%22service_foo%22, %22method_bar%22);%0A  %7D%0A%0A  @Deprecated%0A  private static %3CReqT, RespT%3E MethodDescriptor%3CReqT, RespT%3E noopMethod(%0A      String serviceName, String methodName) %7B%0A    return MethodDescriptor.%3CReqT, RespT%3EnewBuilder()%0A        .setType(MethodType.UNARY)%0A        .setFullMethodName(MethodDescriptor.generateFullMethodName(serviceName, methodName))%0A        .setRequestMarshaller(TestMethodDescriptors.%3CReqT%3EnoopMarshaller())%0A        .setResponseMarshaller(TestMethodDescriptors.%3CRespT%3EnoopMarshaller())%0A        .build();%0A  %7D%0A%0A  /**%0A   * Creates a new marshaller that does nothing.%0A   *%0A   * @since 1.1.0%0A   */%0A  @ExperimentalApi(%22https://github.com/grpc/grpc-java/issues/2600%22)%0A  public static MethodDescriptor.Marshaller%3CVoid%3E voidMarshaller() %7B%0A    return new NoopMarshaller%3CVoid%3E();%0A  %7D%0A%0A  /**%0A   * Creates a new marshaller that does nothing.%0A   *%0A   * @deprecated Use %7B@link #voidMarshaller()%7D instead or implement/mock one%0A   * @since 1.1.0%0A   */%0A  @Deprecated%0A  @ExperimentalApi(%22https://github.com/grpc/grpc-java/issues/2600%22)%0A  public static %3CT%3E MethodDescriptor.Marshaller%3CT%3E noopMarshaller() %7B%0A    return new NoopMarshaller%3CT%3E
+arshaller that does nothing.%0A   *%0A   * @since 1.1.0%0A   */%0A  @ExperimentalApi(%22https://github.com/grpc/grpc-java/issues/2600%22)%0A  public static MethodDescriptor.Marshaller%3CVoid%3E voidMarshaller() %7B%0A    return new NoopMarshaller
 ();%0A
@@ -2071,19 +2071,16 @@
 rshaller
-%3CT%3E
  impleme
@@ -2111,17 +2111,20 @@
 shaller%3C
-T
+Void
 %3E %7B%0A    
@@ -2163,17 +2163,20 @@
  stream(
-T
+Void
  value) 
@@ -2262,17 +2262,20 @@
  public 
-T
+Void
  parse(I

remove deprecated noopMethodDescriptor