File tree 3 files changed +23
-5
lines changed
3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -656,8 +656,14 @@ private static String parseAsciiStringSlow(byte[] value) {
656
656
* additional fields may be added to Status in the future.
657
657
*/
658
658
@ 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 );
661
667
}
662
668
663
669
/**
@@ -667,6 +673,6 @@ public boolean equals(Object obj) {
667
673
*/
668
674
@ Override
669
675
public int hashCode () {
670
- return super .hashCode ();
676
+ return Objects .hashCode (code , description , cause );
671
677
}
672
678
}
Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ public void equals_differentStatuses() {
61
61
@ Test
62
62
public void equals_sameStatuses () {
63
63
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" )));
64
66
}
65
67
66
68
@ Test
Original file line number Diff line number Diff line change 17
17
package io .grpc ;
18
18
19
19
import static org .junit .Assert .assertEquals ;
20
+ import static org .junit .Assert .assertNotEquals ;
20
21
import static org .junit .Assert .assertSame ;
21
22
22
23
import io .grpc .Status .Code ;
@@ -51,15 +52,24 @@ public void sameCauseReturnsSelf() {
51
52
assertSame (Status .CANCELLED , Status .CANCELLED .withCause (null ));
52
53
}
53
54
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
+ }
63
+
54
64
@ Test
55
65
public void sameDescriptionReturnsSelf () {
56
66
assertSame (Status .CANCELLED , Status .CANCELLED .withDescription (null ));
57
67
assertSame (Status .CANCELLED , Status .CANCELLED .augmentDescription (null ));
58
68
}
59
69
60
70
@ Test
61
- public void useObjectHashCode () {
62
- assertEquals (Status .CANCELLED .hashCode (), System .identityHashCode (Status .CANCELLED ));
71
+ public void notUseObjectHashCode () {
72
+ assertNotEquals (Status .CANCELLED .hashCode (), System .identityHashCode (Status .CANCELLED ));
63
73
}
64
74
65
75
@ Test
You can’t perform that action at this time.
0 commit comments