Add faulty principal name to thrown Exception
This is part of the effort to fix b/12070151.
diff --git a/src/com/google/enterprise/adaptor/Principal.java b/src/com/google/enterprise/adaptor/Principal.java
index 043fbd8..cae31a0 100644
--- a/src/com/google/enterprise/adaptor/Principal.java
+++ b/src/com/google/enterprise/adaptor/Principal.java
@@ -33,7 +33,8 @@
throw new IllegalArgumentException("name cannot be empty");
}
if (!n.trim().equals(n)) {
- throw new IllegalArgumentException("name cannot start or end with space");
+ throw new IllegalArgumentException("name \"" + n
+ + "\" should not start or end with space");
}
name = n;
namespace = ns;
diff --git a/test/com/google/enterprise/adaptor/PrincipalTest.java b/test/com/google/enterprise/adaptor/PrincipalTest.java
index a723f6e..a55eb9f 100644
--- a/test/com/google/enterprise/adaptor/PrincipalTest.java
+++ b/test/com/google/enterprise/adaptor/PrincipalTest.java
@@ -86,6 +86,62 @@
}
@Test
+ public void testEmptyNameOfUser() {
+ thrown.expect(IllegalArgumentException.class);
+ new UserPrincipal("");
+ }
+
+ @Test
+ public void testEmptyNameOfGroup() {
+ thrown.expect(IllegalArgumentException.class);
+ new GroupPrincipal("");
+ }
+
+ @Test
+ public void testLeadingSpaceOfUser() {
+ thrown.expect(IllegalArgumentException.class);
+ new UserPrincipal(" yowser");
+ }
+
+ @Test
+ public void testLeadingSpaceOfGroup() {
+ thrown.expect(IllegalArgumentException.class);
+ new GroupPrincipal(" gooop");
+ }
+
+ @Test
+ public void testTrailingSpaceOfUser() {
+ thrown.expect(IllegalArgumentException.class);
+ new UserPrincipal("yowser ");
+ }
+
+ @Test
+ public void testTrailingSpaceOfGroup() {
+ thrown.expect(IllegalArgumentException.class);
+ new GroupPrincipal("gooop ");
+ }
+
+ @Test
+ public void testLeadingSpaceOfUserNameExceptionContainsName() {
+ try {
+ new UserPrincipal(" yowser");
+ fail("Expected IllegalArgumentException not thrown.");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.toString().contains("\" yowser\""));
+ }
+ }
+
+ @Test
+ public void testTrailingSpaceOfGroupNameExceptionContainsName() {
+ try {
+ new GroupPrincipal("gooop ");
+ fail("Expected IllegalArgumentException not thrown.");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.toString().contains("\"gooop \""));
+ }
+ }
+
+ @Test
public void testUserEquals() {
Principal p1 = new UserPrincipal("id");
assertFalse(p1.equals(null));