1
0
mirror of synced 2026-08-05 17:57:15 +00:00

Improved ConfigAttributeEditor so it trims preceding and trailing spaces.

This commit is contained in:
Ben Alex
2004-08-25 21:43:00 +00:00
parent 3f87849f31
commit 5cd65887d5
3 changed files with 29 additions and 1 deletions
@@ -23,6 +23,11 @@ import java.beans.PropertyEditorSupport;
/**
* A property editor that can create a populated {@link
* ConfigAttributeDefinition} from a comma separated list of values.
*
* <P>
* Trims preceding and trailing spaces from presented command separated tokens,
* as this can be a source of hard-to-spot configuration issues for end users.
* </p>
*
* @author Ben Alex
* @version $Id$
@@ -39,7 +44,7 @@ public class ConfigAttributeEditor extends PropertyEditorSupport {
for (int i = 0; i < tokens.length; i++) {
configDefinition.addConfigAttribute(new SecurityConfig(
tokens[i]));
tokens[i].trim()));
}
setValue(configDefinition);
@@ -17,6 +17,7 @@ package net.sf.acegisecurity;
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.Iterator;
@@ -126,6 +127,27 @@ public class ConfigAttributeEditorTests extends TestCase {
assertTrue(result == null);
}
public void testStripsTrailingAndLeadingSpaces() {
ConfigAttributeEditor editor = new ConfigAttributeEditor();
editor.setAsText(" HELLO, DOCTOR,NAME, YESTERDAY ,TOMORROW ");
ConfigAttributeDefinition result = (ConfigAttributeDefinition) editor
.getValue();
Iterator iter = result.getConfigAttributes();
ArrayList list = new ArrayList();
while (iter.hasNext()) {
list.add(iter.next());
}
assertEquals("HELLO", ((ConfigAttribute) list.get(0)).getAttribute());
assertEquals("DOCTOR", ((ConfigAttribute) list.get(1)).getAttribute());
assertEquals("NAME", ((ConfigAttribute) list.get(2)).getAttribute());
assertEquals("YESTERDAY", ((ConfigAttribute) list.get(3)).getAttribute());
assertEquals("TOMORROW", ((ConfigAttribute) list.get(4)).getAttribute());
}
public void testToString() {
ConfigAttributeEditor editor = new ConfigAttributeEditor();
editor.setAsText("KOALA,KANGAROO,EMU,WOMBAT");