Fadelis / grpcmock

A gRPC Java testing tool to easily mock endpoints of gRPC services for IT or Unit testing
http://grpcmock.org
Apache License 2.0
144 stars 13 forks source link

Doesn't work with StatusRuntimeException! #16

Closed draugrmorar closed 2 years ago

draugrmorar commented 2 years ago

Doesn't work with StatusRuntimeException! Our Grpc Service throw StatusRuntimeException. I tried your GrpcMock and i can't to throw exception from stubFor. I saw that i can return Status, but not Exception. Please, help me) May be in your library it is impossible?

draugrmorar commented 2 years ago

I found answer on my question! Thank you for your work.

May be for somebody it will be useful:

    stubFor(unaryMethod(UserGrpc.getCreateUserMethod())
            .willReturn(new ExceptionResponseActionBuilderImpl(
                    new StatusRuntimeException(Status.INVALID_ARGUMENT, getErrorMetadata(111, "Error")
                    )))
    );
Fadelis commented 2 years ago

@Radnaeva there's a method to return any expection: https://github.com/Fadelis/grpcmock/blob/2ffbbbca6d8e030a0da15218e90d3ca21ef38d80/grpcmock-core/src/main/java/org/grpcmock/GrpcMock.java#L318