-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add equals and hashCode to WindowsPrincipal
- Loading branch information
1 parent
35e90a0
commit 7eee2f0
Showing
4 changed files
with
103 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
Source/JNA/waffle-jna/src/test/java/waffle/servlet/WindowsPrincipalTest.java
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
Source/JNA/waffle-jna/src/test/java/waffle/servlet/WindowsPrincipalTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Waffle (https://github.com/dblock/waffle) | ||
* | ||
* Copyright (c) 2010 - 2015 Application Security, Inc. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Application Security, Inc. | ||
*/ | ||
package waffle.servlet; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import mockit.Expectations; | ||
import mockit.Mocked; | ||
import waffle.windows.auth.IWindowsAccount; | ||
import waffle.windows.auth.IWindowsIdentity; | ||
|
||
/** | ||
* The Class WindowsPrincipalTest. | ||
* | ||
* @author dblock[at]dblock[dot]org | ||
*/ | ||
public class WindowsPrincipalTests { | ||
|
||
/** The Constant TEST_FQN. */ | ||
private static final String TEST_FQN = "ACME\\john.smith"; | ||
|
||
/** The windows identity. */ | ||
@Mocked | ||
IWindowsIdentity windowsIdentity; | ||
|
||
/** | ||
* Test to string. | ||
*/ | ||
@Test | ||
public void testToString() { | ||
Assert.assertNotNull(new Expectations() { | ||
{ | ||
WindowsPrincipalTests.this.windowsIdentity.getFqn(); | ||
this.result = WindowsPrincipalTests.TEST_FQN; | ||
WindowsPrincipalTests.this.windowsIdentity.getGroups(); | ||
this.result = new IWindowsAccount[0]; | ||
} | ||
}); | ||
final WindowsPrincipal principal = new WindowsPrincipal(this.windowsIdentity); | ||
Assert.assertEquals(WindowsPrincipalTests.TEST_FQN, principal.getName()); | ||
Assert.assertEquals(WindowsPrincipalTests.TEST_FQN, principal.toString()); | ||
} | ||
|
||
/** | ||
* Test equals and hash code. | ||
*/ | ||
@Test | ||
public void testEqualsAndHashCode() { | ||
Assert.assertNotNull(new Expectations() { | ||
{ | ||
WindowsPrincipalTests.this.windowsIdentity.getFqn(); | ||
this.result = WindowsPrincipalTests.TEST_FQN; | ||
WindowsPrincipalTests.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(), WindowsPrincipalTests.TEST_FQN.hashCode()); | ||
} | ||
|
||
} |