Skip to content

Commit

Permalink
more tests (ref #373)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmlet committed Sep 4, 2023
1 parent 13bbfbc commit 11d1660
Showing 1 changed file with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ static class CustomService extends CustomServiceGrpc.CustomServiceImplBase {

@Override
public void anotherCustom(Custom.CustomRequest request, StreamObserver<Custom.CustomReply> responseObserver) {
if("NPE".equals(request.getName())){
if ("NPE".equals(request.getName())) {
ExceptionUtilsKt.throwException(new NullPointerException());
}
ExceptionUtilsKt.throwException(Status.FAILED_PRECONDITION);
if ("RT_ERROR".equals(request.getName())) {
responseObserver.onError(Status.NOT_FOUND.asRuntimeException());
}
if ("ERROR".equals(request.getName())) {
responseObserver.onError(Status.OUT_OF_RANGE.asException());
} else {
ExceptionUtilsKt.throwException(Status.FAILED_PRECONDITION);
}
}

@Override
Expand All @@ -65,8 +72,9 @@ public void custom(Custom.CustomRequest request, StreamObserver<Custom.CustomRep
public StreamObserver<Custom.CustomRequest> customStream(StreamObserver<Custom.CustomReply> responseObserver) {
throw new StatusRuntimeException(Status.FAILED_PRECONDITION);
}

@GRpcExceptionHandler
public Status handle(NullPointerException e, GRpcExceptionScope scope ){
public Status handle(NullPointerException e, GRpcExceptionScope scope) {
return Status.DATA_LOSS;
}

Expand Down Expand Up @@ -129,4 +137,22 @@ public void npeExceptionTest() {
assertThat(statusRuntimeException.getStatus(), is(Status.DATA_LOSS));
}

@Test
public void errorExceptionTest() {
final StatusRuntimeException statusRuntimeException = assertThrows(StatusRuntimeException.class, () ->
CustomServiceGrpc.newBlockingStub(getChannel()).anotherCustom(
Custom.CustomRequest.newBuilder().setName("ERROR").build()
)
);
assertThat(statusRuntimeException.getStatus(), is(Status.OUT_OF_RANGE));
}
public void rtErrorExceptionTest() {
final StatusRuntimeException statusRuntimeException = assertThrows(StatusRuntimeException.class, () ->
CustomServiceGrpc.newBlockingStub(getChannel()).anotherCustom(
Custom.CustomRequest.newBuilder().setName("RT_ERROR").build()
)
);
assertThat(statusRuntimeException.getStatus(), is(Status.NOT_FOUND));
}

}

0 comments on commit 11d1660

Please sign in to comment.