Skip to content

Commit 164e3cb

Browse files
committed
Replace hashcode assertions with equaility assertions, backed by equalsverifier contract test. this resolves the hardcoded hashcodes causing stochastic test failures depending on execution order/enviroment, test cleanup to follow
1 parent 697b8c9 commit 164e3cb

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/test/java/us/kbase/test/auth2/lib/EmailAddressTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class EmailAddressTest {
1919
public void construct() throws Exception {
2020
final EmailAddress ea = new EmailAddress(" [email protected] \n");
2121
assertThat("incorrect email", ea.getAddress(), is("[email protected]"));
22-
assertThat("incorrect hashCode", ea.hashCode(), is(1827947467));
22+
assertThat("incorrect equality", ea, is(new EmailAddress("[email protected]")));
2323
assertThat("incorrect toString", ea.toString(), is("EmailAddress [[email protected]]"));
2424
}
2525

src/test/java/us/kbase/test/auth2/lib/UserNameTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public void root() throws Exception {
2424
assertThat("incorrect username", un.getName(), is("***ROOT***"));
2525
assertThat("incorrect is root", un.isRoot(), is(true));
2626
assertThat("incorrect toString", un.toString(), is("UserName [getName()=***ROOT***]"));
27-
assertThat("incorrect hashCode" , un.hashCode(), is(-280622915));
28-
27+
assertThat("incorrect equality", un, is(UserName.ROOT));
28+
2929
final UserName un2 = UserName.ROOT;
3030
assertThat("incorrect username", un2.getName(), is("***ROOT***"));
3131
assertThat("incorrect is root", un2.isRoot(), is(true));
3232
assertThat("incorrect toString", un2.toString(), is("UserName [getName()=***ROOT***]"));
33-
assertThat("incorrect hashCode" , un2.hashCode(), is(-280622915));
33+
assertThat("incorrect equality", un2, is(new UserName("***ROOT***")));
3434
}
3535

3636
@Test
@@ -39,7 +39,7 @@ public void construct() throws Exception {
3939
assertThat("incorrect username", un.getName(), is("a8nba9"));
4040
assertThat("incorrect is root", un.isRoot(), is(false));
4141
assertThat("incorrect toString", un.toString(), is("UserName [getName()=a8nba9]"));
42-
assertThat("incorrect hashCode" , un.hashCode(), is(-1462848190));
42+
assertThat("incorrect equality", un, is(new UserName("a8nba9")));
4343
}
4444

4545
@Test

src/test/java/us/kbase/test/auth2/lib/identity/RemoteIdentityTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void remoteDetailsWithAllFields() throws Exception {
2222
assertThat("incorrect fullname", dets.getFullname(), is("full"));
2323
assertThat("incorrect email", dets.getEmail(), is("email"));
2424
assertThat("incorrect mfa authenticated", dets.getMfa(), is(MfaStatus.UNKNOWN));
25-
assertThat("incorrect hashcode", dets.hashCode(), is(44648981));
25+
assertThat("incorrect equality", dets, is(new RemoteIdentityDetails("user", "full", "email")));
2626
assertThat("incorrect toString()", dets.toString(),
2727
is("RemoteIdentityDetails [username=user, fullname=full, email=email, mfa=UNKNOWN]"));
2828
}
@@ -34,16 +34,15 @@ public void remoteDetailsWithEmptyFields() throws Exception {
3434
assertThat("incorrect fullname", dets.getFullname(), is((String) null));
3535
assertThat("incorrect email", dets.getEmail(), is((String) null));
3636
assertThat("incorrect mfa authenticated", dets.getMfa(), is(MfaStatus.UNKNOWN));
37-
assertThat("incorrect hashcode", dets.hashCode(), is(547016802));
3837
assertThat("incorrect toString()", dets.toString(),
3938
is("RemoteIdentityDetails [username=user, fullname=null, email=null, mfa=UNKNOWN]"));
40-
39+
4140
final RemoteIdentityDetails dets2 = new RemoteIdentityDetails("user", null, null);
4241
assertThat("incorrect username", dets2.getUsername(), is("user"));
4342
assertThat("incorrect fullname", dets2.getFullname(), is((String) null));
4443
assertThat("incorrect email", dets2.getEmail(), is((String) null));
4544
assertThat("incorrect mfa authenticated", dets2.getMfa(), is(MfaStatus.UNKNOWN));
46-
assertThat("incorrect hashcode", dets2.hashCode(), is(547016802));
45+
assertThat("incorrect equality", dets2, is(dets));
4746
assertThat("incorrect toString()", dets2.toString(),
4847
is("RemoteIdentityDetails [username=user, fullname=null, email=null, mfa=UNKNOWN]"));
4948
}
@@ -77,7 +76,7 @@ public void remoteId() throws Exception {
7776
assertThat("incorrect unique id", id.getID(), is("5c7d96a3dd7a87850a2ef34087565a6e"));
7877
// check unique id again to check memoization doesn't change result
7978
assertThat("incorrect unique id", id.getID(), is("5c7d96a3dd7a87850a2ef34087565a6e"));
80-
assertThat("incorrect hashcode", id.hashCode(), is(3118804));
79+
assertThat("incorrect equality", id, is(new RemoteIdentityID("foo", "bar")));
8180
assertThat("incorrect toString()", id.toString(),
8281
is("RemoteIdentityID [provider=foo, id=bar]"));
8382
}
@@ -116,7 +115,8 @@ public void identity() throws Exception {
116115
final RemoteIdentity ri = new RemoteIdentity(id, dets);
117116
assertThat("incorrect id", ri.getRemoteID(), is(id));
118117
assertThat("incorrect details", ri.getDetails(), is(dets));
119-
assertThat("incorrect hashcode", ri.hashCode(), is(-237603620));
118+
assertThat("incorrect equality", ri, is(new RemoteIdentity(
119+
new RemoteIdentityID("p", "i"), new RemoteIdentityDetails("u", "f", "e"))));
120120
assertThat("incorrect toString()", ri.toString(),
121121
is("RemoteIdentity [remoteID=RemoteIdentityID [provider=p, id=i], " +
122122
"details=RemoteIdentityDetails [username=u, fullname=f, email=e, mfa=UNKNOWN]]"));

0 commit comments

Comments
 (0)