Skip to content

Commit

Permalink
Improve handle grpc runtime exception test
Browse files Browse the repository at this point in the history
  • Loading branch information
FliegenKLATSCH committed Mar 24, 2024
1 parent d440b55 commit 661a14a
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ private ManagedChannel createSecuredChannel(int port) throws SSLException {
@Test
public void gRPCUnaryCallShouldHandleRuntimeException() throws SSLException {
ManagedChannel channel = createSecuredChannel(gatewayPort);
boolean thrown = false;

try {
HelloServiceGrpc.newBlockingStub(channel)
.hello(HelloRequest.newBuilder().setFirstName("failWithRuntimeException!").build());
}
catch (StatusRuntimeException e) {
Assertions.assertThat(FAILED_PRECONDITION.getCode()).isEqualTo(e.getStatus().getCode());
Assertions.assertThat("Invalid firstName").isEqualTo(e.getStatus().getDescription());
thrown = true;
Assertions.assertThat(e.getStatus().getCode()).isEqualTo(FAILED_PRECONDITION.getCode());
Assertions.assertThat(e.getStatus().getDescription()).isEqualTo("Invalid firstName");
}
Assertions.assertThat(thrown).withFailMessage("Expected exception not thrown!").isTrue();
}

@Test
Expand Down

0 comments on commit 661a14a

Please sign in to comment.