@Test public void shouldSupplyHandlerForResponseOnly() { UnaryMethodHandlerSupplier supplier = new UnaryMethodHandlerSupplier(); AnnotatedMethod method = getMethod("responseOnly"); UnaryService service = mock(UnaryService.class); when(service.responseOnly()).thenReturn(19L); MethodHandler<String, Long> handler = supplier.get("foo", method, () -> service); assertThat(handler, is(notNullValue())); assertThat(handler.getRequestType(), equalTo(Empty.class)); assertThat(handler.getResponseType(), equalTo(Long.class)); assertThat(handler.type(), equalTo(MethodDescriptor.MethodType.UNARY)); StreamObserver<Long> observer = mock(StreamObserver.class); handler.invoke("foo", observer); verify(service).responseOnly(); verify(observer).onNext(19L); }
@Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; }
UnaryMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; } }
UnaryMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; } UnaryMethodHandlerSupplier(); }
UnaryMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; } UnaryMethodHandlerSupplier(); @Override boolean supplies(AnnotatedMethod method); @Override MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance); }
UnaryMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; } UnaryMethodHandlerSupplier(); @Override boolean supplies(AnnotatedMethod method); @Override MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance);  }