File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed
Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -656,8 +656,14 @@ private static String parseAsciiStringSlow(byte[] value) {
656656 * additional fields may be added to Status in the future.
657657 */
658658 @ Override
659- public boolean equals (Object obj ) {
660- return super .equals (obj );
659+ public boolean equals (Object o ) {
660+ if (!(o instanceof Status )) {
661+ return false ;
662+ }
663+ Status status = (Status ) o ;
664+ return code == status .code
665+ && Objects .equal (description , status .description )
666+ && Objects .equal (cause , status .cause );
661667 }
662668
663669 /**
@@ -667,6 +673,6 @@ public boolean equals(Object obj) {
667673 */
668674 @ Override
669675 public int hashCode () {
670- return super .hashCode ();
676+ return Objects .hashCode (code , description , cause );
671677 }
672678}
Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ public void equals_differentStatuses() {
6161 @ Test
6262 public void equals_sameStatuses () {
6363 assertThat (StatusOr .fromStatus (Status .ABORTED )).isEqualTo (StatusOr .fromStatus (Status .ABORTED ));
64+ assertThat (StatusOr .fromStatus (Status .ABORTED .withDescription ("aborted" )))
65+ .isEqualTo (StatusOr .fromStatus (Status .ABORTED .withDescription ("aborted" )));
6466 }
6567
6668 @ Test
Original file line number Diff line number Diff line change 1717package io .grpc ;
1818
1919import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertNotEquals ;
2021import static org .junit .Assert .assertSame ;
2122
2223import io .grpc .Status .Code ;
@@ -51,15 +52,25 @@ public void sameCauseReturnsSelf() {
5152 assertSame (Status .CANCELLED , Status .CANCELLED .withCause (null ));
5253 }
5354
55+ @ Test
56+ public void equalsStatus () {
57+ IllegalStateException ex = new IllegalStateException ("The operation was aborted" );
58+ assertEquals (Status .ABORTED .withDescription ("The operation was aborted" )
59+ .withCause (ex ),
60+ Status .ABORTED .withDescription ("The operation was aborted" )
61+ .withCause (ex ));
62+ assertNotEquals (Status .ABORTED .withDescription ("The operation was aborted" ), null );
63+ }
64+
5465 @ Test
5566 public void sameDescriptionReturnsSelf () {
5667 assertSame (Status .CANCELLED , Status .CANCELLED .withDescription (null ));
5768 assertSame (Status .CANCELLED , Status .CANCELLED .augmentDescription (null ));
5869 }
5970
6071 @ Test
61- public void useObjectHashCode () {
62- assertEquals (Status .CANCELLED .hashCode (), System .identityHashCode (Status .CANCELLED ));
72+ public void notUseObjectHashCode () {
73+ assertNotEquals (Status .CANCELLED .hashCode (), System .identityHashCode (Status .CANCELLED ));
6374 }
6475
6576 @ Test
You can’t perform that action at this time.
0 commit comments