@@ -483,7 +483,7 @@ public void clientCompressedUnary(boolean probe) throws Exception {
483483 blockingStub .unaryCall (expectCompressedRequest );
484484 fail ("expected INVALID_ARGUMENT" );
485485 } catch (StatusRuntimeException e ) {
486- assertEquals (Status .INVALID_ARGUMENT . getCode () , e .getStatus (). getCode ());
486+ assertCodeEquals (Status .Code . INVALID_ARGUMENT , e .getStatus ());
487487 }
488488 assertStatsTrace ("grpc.testing.TestService/UnaryCall" , Status .Code .INVALID_ARGUMENT );
489489 }
@@ -652,7 +652,7 @@ public void clientCompressedStreaming(boolean probe) throws Exception {
652652 responseObserver .awaitCompletion (operationTimeoutMillis (), TimeUnit .MILLISECONDS );
653653 Throwable e = responseObserver .getError ();
654654 assertNotNull ("expected INVALID_ARGUMENT" , e );
655- assertEquals (Status .INVALID_ARGUMENT . getCode () , Status .fromThrowable (e ). getCode ( ));
655+ assertCodeEquals (Status .Code . INVALID_ARGUMENT , Status .fromThrowable (e ));
656656 }
657657
658658 // Start a new stream
@@ -801,8 +801,7 @@ public void cancelAfterBegin() throws Exception {
801801 requestObserver .onError (new RuntimeException ());
802802 responseObserver .awaitCompletion ();
803803 assertEquals (Arrays .<StreamingInputCallResponse >asList (), responseObserver .getValues ());
804- assertEquals (Status .Code .CANCELLED ,
805- Status .fromThrowable (responseObserver .getError ()).getCode ());
804+ assertCodeEquals (Status .Code .CANCELLED , Status .fromThrowable (responseObserver .getError ()));
806805
807806 if (metricsExpected ()) {
808807 MetricsRecord clientStartRecord = clientStatsRecorder .pollRecord (5 , TimeUnit .SECONDS );
@@ -839,8 +838,7 @@ public void cancelAfterFirstResponse() throws Exception {
839838 requestObserver .onError (new RuntimeException ());
840839 responseObserver .awaitCompletion (operationTimeoutMillis (), TimeUnit .MILLISECONDS );
841840 assertEquals (1 , responseObserver .getValues ().size ());
842- assertEquals (Status .Code .CANCELLED ,
843- Status .fromThrowable (responseObserver .getError ()).getCode ());
841+ assertCodeEquals (Status .Code .CANCELLED , Status .fromThrowable (responseObserver .getError ()));
844842
845843 assertStatsTrace ("grpc.testing.TestService/FullDuplexCall" , Status .Code .CANCELLED );
846844 }
@@ -1107,7 +1105,7 @@ public void deadlineExceeded() throws Exception {
11071105 stub .streamingOutputCall (request ).next ();
11081106 fail ("Expected deadline to be exceeded" );
11091107 } catch (StatusRuntimeException ex ) {
1110- assertEquals (Status .DEADLINE_EXCEEDED . getCode () , ex .getStatus (). getCode ());
1108+ assertCodeEquals (Status .Code . DEADLINE_EXCEEDED , ex .getStatus ());
11111109 String desc = ex .getStatus ().getDescription ();
11121110 assertTrue (desc ,
11131111 // There is a race between client and server-side deadline expiration.
@@ -1153,8 +1151,7 @@ public void deadlineExceededServerStreaming() throws Exception {
11531151 .withDeadlineAfter (30 , TimeUnit .MILLISECONDS )
11541152 .streamingOutputCall (request , recorder );
11551153 recorder .awaitCompletion ();
1156- assertEquals (Status .DEADLINE_EXCEEDED .getCode (),
1157- Status .fromThrowable (recorder .getError ()).getCode ());
1154+ assertCodeEquals (Status .Code .DEADLINE_EXCEEDED , Status .fromThrowable (recorder .getError ()));
11581155 if (metricsExpected ()) {
11591156 // Stream may not have been created when deadline is exceeded, thus we don't check tracer
11601157 // stats.
@@ -1179,7 +1176,7 @@ public void deadlineInPast() throws Exception {
11791176 .emptyCall (Empty .getDefaultInstance ());
11801177 fail ("Should have thrown" );
11811178 } catch (StatusRuntimeException ex ) {
1182- assertEquals (Status .Code .DEADLINE_EXCEEDED , ex .getStatus (). getCode ());
1179+ assertCodeEquals (Status .Code .DEADLINE_EXCEEDED , ex .getStatus ());
11831180 assertThat (ex .getStatus ().getDescription ())
11841181 .startsWith ("ClientCall started after CallOptions deadline was exceeded" );
11851182 }
@@ -1212,7 +1209,7 @@ public void deadlineInPast() throws Exception {
12121209 .emptyCall (Empty .getDefaultInstance ());
12131210 fail ("Should have thrown" );
12141211 } catch (StatusRuntimeException ex ) {
1215- assertEquals (Status .Code .DEADLINE_EXCEEDED , ex .getStatus (). getCode ());
1212+ assertCodeEquals (Status .Code .DEADLINE_EXCEEDED , ex .getStatus ());
12161213 assertThat (ex .getStatus ().getDescription ())
12171214 .startsWith ("ClientCall started after CallOptions deadline was exceeded" );
12181215 }
@@ -1278,8 +1275,7 @@ public void maxInboundSize_tooBig() {
12781275 stub .streamingOutputCall (request ).next ();
12791276 fail ();
12801277 } catch (StatusRuntimeException ex ) {
1281- Status s = ex .getStatus ();
1282- assertWithMessage (s .toString ()).that (s .getCode ()).isEqualTo (Status .Code .RESOURCE_EXHAUSTED );
1278+ assertCodeEquals (Status .Code .RESOURCE_EXHAUSTED , ex .getStatus ());
12831279 assertThat (Throwables .getStackTraceAsString (ex )).contains ("exceeds maximum" );
12841280 }
12851281 }
@@ -1334,8 +1330,7 @@ public void maxOutboundSize_tooBig() {
13341330 stub .streamingOutputCall (request ).next ();
13351331 fail ();
13361332 } catch (StatusRuntimeException ex ) {
1337- Status s = ex .getStatus ();
1338- assertWithMessage (s .toString ()).that (s .getCode ()).isEqualTo (Status .Code .CANCELLED );
1333+ assertCodeEquals (Status .Code .CANCELLED , ex .getStatus ());
13391334 assertThat (Throwables .getStackTraceAsString (ex )).contains ("message too large" );
13401335 }
13411336 }
@@ -1557,7 +1552,7 @@ public void statusCodeAndMessage() throws Exception {
15571552 blockingStub .unaryCall (simpleRequest );
15581553 fail ();
15591554 } catch (StatusRuntimeException e ) {
1560- assertEquals (Status .UNKNOWN . getCode () , e .getStatus (). getCode ());
1555+ assertCodeEquals (Status .Code . UNKNOWN , e .getStatus ());
15611556 assertEquals (errorMessage , e .getStatus ().getDescription ());
15621557 }
15631558 assertStatsTrace ("grpc.testing.TestService/UnaryCall" , Status .Code .UNKNOWN );
@@ -1573,7 +1568,7 @@ public void statusCodeAndMessage() throws Exception {
15731568 .isTrue ();
15741569 assertThat (responseObserver .getError ()).isNotNull ();
15751570 Status status = Status .fromThrowable (responseObserver .getError ());
1576- assertEquals (Status .UNKNOWN . getCode () , status . getCode () );
1571+ assertCodeEquals (Status .Code . UNKNOWN , status );
15771572 assertEquals (errorMessage , status .getDescription ());
15781573 assertStatsTrace ("grpc.testing.TestService/FullDuplexCall" , Status .Code .UNKNOWN );
15791574 }
@@ -1593,7 +1588,7 @@ public void specialStatusMessage() throws Exception {
15931588 blockingStub .unaryCall (simpleRequest );
15941589 fail ();
15951590 } catch (StatusRuntimeException e ) {
1596- assertEquals (Status .UNKNOWN . getCode () , e .getStatus (). getCode ());
1591+ assertCodeEquals (Status .Code . UNKNOWN , e .getStatus ());
15971592 assertEquals (errorMessage , e .getStatus ().getDescription ());
15981593 }
15991594 assertStatsTrace ("grpc.testing.TestService/UnaryCall" , Status .Code .UNKNOWN );
@@ -1606,7 +1601,7 @@ public void unimplementedMethod() {
16061601 blockingStub .unimplementedCall (Empty .getDefaultInstance ());
16071602 fail ();
16081603 } catch (StatusRuntimeException e ) {
1609- assertEquals (Status .UNIMPLEMENTED . getCode () , e .getStatus (). getCode ());
1604+ assertCodeEquals (Status .Code . UNIMPLEMENTED , e .getStatus ());
16101605 }
16111606
16121607 assertClientStatsTrace ("grpc.testing.TestService/UnimplementedCall" ,
@@ -1622,7 +1617,7 @@ public void unimplementedService() {
16221617 stub .unimplementedCall (Empty .getDefaultInstance ());
16231618 fail ();
16241619 } catch (StatusRuntimeException e ) {
1625- assertEquals (Status .UNIMPLEMENTED . getCode () , e .getStatus (). getCode ());
1620+ assertCodeEquals (Status .Code . UNIMPLEMENTED , e .getStatus ());
16261621 }
16271622
16281623 assertStatsTrace ("grpc.testing.UnimplementedService/UnimplementedCall" ,
@@ -1652,8 +1647,8 @@ public void timeoutOnSleepingServer() throws Exception {
16521647
16531648 assertTrue (responseObserver .awaitCompletion (operationTimeoutMillis (), TimeUnit .MILLISECONDS ));
16541649 assertEquals (0 , responseObserver .getValues ().size ());
1655- assertEquals ( Status . DEADLINE_EXCEEDED . getCode (),
1656- Status .fromThrowable (responseObserver .getError ()). getCode ( ));
1650+ assertCodeEquals (
1651+ Status . Code . DEADLINE_EXCEEDED , Status .fromThrowable (responseObserver .getError ()));
16571652
16581653 if (metricsExpected ()) {
16591654 // CensusStreamTracerModule record final status in the interceptor, thus is guaranteed to be
@@ -2035,6 +2030,10 @@ private void assertPayload(Payload expected, Payload actual) {
20352030 }
20362031 }
20372032
2033+ private static void assertCodeEquals (Status .Code expected , Status actual ) {
2034+ assertWithMessage ("Unexpected status: %s" , actual ).that (actual .getCode ()).isEqualTo (expected );
2035+ }
2036+
20382037 /**
20392038 * Captures the request attributes. Useful for testing ServerCalls.
20402039 * {@link ServerCall#getAttributes()}
0 commit comments