@Test public void noTrim() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",",false,false); editor.setAsText(" 0,1 , 2 "); Object value = editor.getValue(); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals(3, array[i].length()); assertEquals("" + i, array[i].trim()); } assertEquals(" 0,1 , 2 ", editor.getAsText()); }
@Test public void trimByDefault() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(); editor.setAsText(" 0,1 , 2 "); Object value = editor.getValue(); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals("" + i, array[i]); } assertEquals("0,1,2", editor.getAsText()); }
@Test public void withCharsToDelete() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", "\r\n", false); editor.setAsText("0\r,1,\n2"); Object value = editor.getValue(); assertTrue(value instanceof String[]); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals("" + i, array[i]); } assertEquals("0,1,2", editor.getAsText()); }
@Test public void withCustomSeparator() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(":"); editor.setAsText("0:1:2"); Object value = editor.getValue(); assertTrue(value instanceof String[]); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals("" + i, array[i]); } assertEquals("0:1:2", editor.getAsText()); }
@Test public void withDefaultSeparator() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(); editor.setAsText("0,1,2"); Object value = editor.getValue(); assertNotNull(value); assertTrue(value instanceof String[]); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals("" + i, array[i]); } assertEquals("0,1,2", editor.getAsText()); }