Skip to content

Commit

Permalink
Merge pull request #310 from aleksandr-m/feature/windows_principal_eq…
Browse files Browse the repository at this point in the history
…uals_hash_code

Add equals and hashCode to WindowsPrincipal
  • Loading branch information
hazendaz committed Jan 17, 2016
2 parents 66a4fe5 + 88b149f commit c2fbdf9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [#268](https://github.com/dblock/waffle/pull/301): Cannot log in automatically on machine where Tomcat service is running
* [#274](https://github.com/dblock/waffle/pull/274): Update WindowsSecurityContextImpl.java to handle SEC_E_BUFFER_TOO_SMALL
* [#128](https://github.com/dblock/waffle/pull/128): Update WindowsSecurityContext.cs to handle SEC_E_BUFFER_TOO_SMALL
* [#310](https://github.com/dblock/waffle/pull/310): Add equals and hashCode to WindowsPrincipal

1.8.0 (09/10/15)
================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,30 @@ public String toString() {
return this.getName();
}

/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}

if (o instanceof WindowsPrincipal) {
return this.getName().equals(((WindowsPrincipal) o).getName());
}

return false;
}

/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return this.getName().hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,31 @@ public void testToString() {
this.result = WindowsPrincipalTest.TEST_FQN;
WindowsPrincipalTest.this.windowsIdentity.getGroups();
this.result = new IWindowsAccount[0];

}
});
final WindowsPrincipal principal = new WindowsPrincipal(this.windowsIdentity);
Assert.assertEquals(WindowsPrincipalTest.TEST_FQN, principal.getName());
Assert.assertEquals(WindowsPrincipalTest.TEST_FQN, principal.toString());
}

/**
* Test equals and hash code.
*/
@Test
public void testEqualsAndHashCode() {
Assert.assertNotNull(new Expectations() {
{
WindowsPrincipalTest.this.windowsIdentity.getFqn();
this.result = WindowsPrincipalTest.TEST_FQN;
WindowsPrincipalTest.this.windowsIdentity.getGroups();
this.result = new IWindowsAccount[0];
}
});
WindowsPrincipal principal = new WindowsPrincipal(this.windowsIdentity);
WindowsPrincipal principal2 = new WindowsPrincipal(this.windowsIdentity);
Assert.assertTrue(principal.equals(principal2) && principal2.equals(principal));
Assert.assertEquals(principal.hashCode(), principal2.hashCode());
Assert.assertEquals(principal.hashCode(), WindowsPrincipalTest.TEST_FQN.hashCode());
}

}

0 comments on commit c2fbdf9

Please sign in to comment.