summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Girardot2010-08-16 11:42:14 (EDT)
committer Steve Powell2010-08-16 11:42:26 (EDT)
commit31a6e18ea6338456d6d3e496f289ba3a23b4cbc6 (patch)
tree8e1940c5ed092e3914b93d0ea532f1c299141a1f
parent6aed63fd535198d320a2be88e63e6388258e5210 (diff)
downloadorg.eclipse.virgo.kernel-31a6e18ea6338456d6d3e496f289ba3a23b4cbc6.zip
org.eclipse.virgo.kernel-31a6e18ea6338456d6d3e496f289ba3a23b4cbc6.tar.gz
org.eclipse.virgo.kernel-31a6e18ea6338456d6d3e496f289ba3a23b4cbc6.tar.bz2
Bug 322424 - Add tests for class org.eclipse.virgo.kernel.authentication.Role
-rw-r--r--org.eclipse.virgo.kernel.authentication/src/test/java/org/eclipse/virgo/kernel/authentication/RoleTests.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.authentication/src/test/java/org/eclipse/virgo/kernel/authentication/RoleTests.java b/org.eclipse.virgo.kernel.authentication/src/test/java/org/eclipse/virgo/kernel/authentication/RoleTests.java
new file mode 100644
index 0000000..ff54d2b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.authentication/src/test/java/org/eclipse/virgo/kernel/authentication/RoleTests.java
@@ -0,0 +1,87 @@
+/* Copyright (c) 2010 Olivier Girardot
+ * 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:
+ * Olivier Girardot - initial contribution
+ */
+
+package org.eclipse.virgo.kernel.authentication;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+
+import java.security.Principal;
+
+import org.junit.Test;
+
+/**
+ * This class is for testing {@link Role} class,
+ * an implementation of the {@link Principal} interface.
+ */
+public class RoleTests {
+
+ private static final String ADMINISTRATOR_ROLE = "Administrator";
+ private static final String TESTER_ROLE = "Tester";
+
+ @Test
+ public void testEqualsWithNull() {
+ assertFalse(new Role(ADMINISTRATOR_ROLE).equals(null));
+ }
+
+ @Test
+ public void testEqualsWithSameReference() {
+ Role adminRole = new Role(ADMINISTRATOR_ROLE);
+ assertTrue(adminRole.equals(adminRole));
+ }
+
+ @Test
+ public void testHashCodeWithSameNullParameters() {
+ Role nullRole = new Role(null);
+ assertEquals((new Role(null)).hashCode(), nullRole.hashCode());
+ }
+
+ @Test
+ public void testHashCodeWithSameNonNullParameters() {
+ Role adminRole = new Role(ADMINISTRATOR_ROLE);
+ assertEquals((new Role(ADMINISTRATOR_ROLE)).hashCode(), adminRole.hashCode());
+ }
+
+ @Test
+ public void testEqualsWithSameNullParameters() {
+ assertTrue(new Role(null).equals(new Role(null)));
+ }
+
+ @Test
+ public void testNotEqualsWithDifferentParameters() {
+ assertFalse(new Role(null).equals(new Role(ADMINISTRATOR_ROLE)));
+ }
+
+ @Test
+ public void testMeaningFullEquals() {
+ Role adminRole = new Role(ADMINISTRATOR_ROLE);
+ Role secAdminRole = new Role(ADMINISTRATOR_ROLE);
+ assertTrue(adminRole.equals(secAdminRole));
+ }
+
+ @Test
+ public void testEqualsWithDifferentParameters() {
+ Role adminRole = new Role(ADMINISTRATOR_ROLE);
+ Role secAdminRole = new Role(TESTER_ROLE);
+ assertFalse(adminRole.equals(secAdminRole));
+ }
+
+ @Test
+ public void testEqualsWithWrongType() {
+ assertFalse(new Role(null).equals(new Object()));
+ }
+
+ @Test
+ public void testToStringWithNull() {
+ assertNull(new Role(null).toString());
+ }
+}