mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-29 15:22:15 +00:00
Correction of equals(Object) and hashCode() methods.
This commit is contained in:
parent
85085abf9e
commit
949205b369
@ -141,11 +141,15 @@ public final class BasePermission implements Permission {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object arg0) {
|
public boolean equals(Object arg0) {
|
||||||
if (!(arg0 instanceof BasePermission)) {
|
if (arg0 == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BasePermission rhs = (BasePermission) arg0;
|
if (!(arg0 instanceof Permission)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Permission rhs = (Permission) arg0;
|
||||||
|
|
||||||
return (this.mask == rhs.getMask());
|
return (this.mask == rhs.getMask());
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,18 @@ public class CumulativePermission implements Permission {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean equals(Object arg0) {
|
public boolean equals(Object arg0) {
|
||||||
if (!(arg0 instanceof CumulativePermission)) {
|
if (arg0 == null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CumulativePermission rhs = (CumulativePermission) arg0;
|
if (!(arg0 instanceof Permission)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Permission rhs = (Permission) arg0;
|
||||||
|
|
||||||
return (this.mask == rhs.getMask());
|
return (this.mask == rhs.getMask());
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.security.acls.domain;
|
package org.springframework.security.acls.domain;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.security.acls.Permission;
|
import org.springframework.security.acls.Permission;
|
||||||
|
|
||||||
|
|
||||||
@ -25,10 +31,13 @@ import org.springframework.security.acls.Permission;
|
|||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @version $Id${date}
|
* @version $Id${date}
|
||||||
*/
|
*/
|
||||||
public class PermissionTests extends TestCase {
|
public class PermissionTests {
|
||||||
|
private static final Log LOGGER = LogFactory.getLog(PermissionTests.class);
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
public void testExpectedIntegerValues() {
|
@Test
|
||||||
|
public void expectedIntegerValues() {
|
||||||
assertEquals(1, BasePermission.READ.getMask());
|
assertEquals(1, BasePermission.READ.getMask());
|
||||||
assertEquals(16, BasePermission.ADMINISTRATION.getMask());
|
assertEquals(16, BasePermission.ADMINISTRATION.getMask());
|
||||||
assertEquals(7,
|
assertEquals(7,
|
||||||
@ -38,14 +47,16 @@ public class PermissionTests extends TestCase {
|
|||||||
new CumulativePermission().set(BasePermission.READ).set(BasePermission.ADMINISTRATION).getMask());
|
new CumulativePermission().set(BasePermission.READ).set(BasePermission.ADMINISTRATION).getMask());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFromInteger() {
|
@Test
|
||||||
|
public void fromInteger() {
|
||||||
Permission permission = BasePermission.buildFromMask(7);
|
Permission permission = BasePermission.buildFromMask(7);
|
||||||
System.out.println("7 = " + permission.toString());
|
System.out.println("7 = " + permission.toString());
|
||||||
permission = BasePermission.buildFromMask(4);
|
permission = BasePermission.buildFromMask(4);
|
||||||
System.out.println("4 = " + permission.toString());
|
System.out.println("4 = " + permission.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStringConversion() {
|
@Test
|
||||||
|
public void stringConversion() {
|
||||||
System.out.println("R = " + BasePermission.READ.toString());
|
System.out.println("R = " + BasePermission.READ.toString());
|
||||||
assertEquals("BasePermission[...............................R=1]", BasePermission.READ.toString());
|
assertEquals("BasePermission[...............................R=1]", BasePermission.READ.toString());
|
||||||
|
|
||||||
@ -79,4 +90,12 @@ public class PermissionTests extends TestCase {
|
|||||||
new CumulativePermission().set(BasePermission.ADMINISTRATION).set(BasePermission.READ)
|
new CumulativePermission().set(BasePermission.ADMINISTRATION).set(BasePermission.READ)
|
||||||
.clear(BasePermission.ADMINISTRATION).clear(BasePermission.READ).toString());
|
.clear(BasePermission.ADMINISTRATION).clear(BasePermission.READ).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user