I'm working on GRPC client for the server. In GRPC repo the advise is to mock a service in a such manner:
private final GreeterGrpc.GreeterImplBase serviceImpl =
mock(GreeterGrpc.GreeterImplBase.class, delegatesTo(
new GreeterGrpc.GreeterImplBase() {
// By default the client will receive Status.UNIMPLEMENTED for all RPCs.
// You might need to implement necessary behaviors for your test here, like this:
//
// @Override
// public void sayHello(HelloRequest request, StreamObserver<HelloReply> respObserver) {
// respObserver.onNext(HelloReply.getDefaultInstance());
// respObserver.onCompleted();
// }
}));
I wonder, what would change if I just replace
mock(GreeterGrpc.GreeterImplBase.class, delegatesTo(
with anonymous class creation like this:
private final GreeterGrpc.GreeterImplBase serviceImpl =
new GreeterGrpc.GreeterImplBase() {
// By default the client will receive Status.UNIMPLEMENTED for all RPCs.
// You might need to implement necessary behaviors for your test here, like this:
//
// @Override
// public void sayHello(HelloRequest request, StreamObserver<HelloReply> respObserver) {
// respObserver.onNext(HelloReply.getDefaultInstance());
// respObserver.onCompleted();
// }
};
I don't see any benefits Mockito can offer here as all calls are delegated to the delegate.
Is it correct or am I missing something?