Polish StringArrayPropertyEditor[Tests]
This commit is contained in:
@@ -23,39 +23,31 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Rick Evans
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class StringArrayPropertyEditorTests {
|
||||
class StringArrayPropertyEditorTests {
|
||||
|
||||
@Test
|
||||
public void withDefaultSeparator() throws Exception {
|
||||
void withDefaultSeparator() {
|
||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor();
|
||||
editor.setAsText("0,1,2");
|
||||
Object value = editor.getValue();
|
||||
assertThat(value).isNotNull();
|
||||
boolean condition = value instanceof String[];
|
||||
assertThat(condition).isTrue();
|
||||
String[] array = (String[]) value;
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
assertThat(array[i]).isEqualTo(("" + i));
|
||||
}
|
||||
assertTrimmedElements(value);
|
||||
assertThat(editor.getAsText()).isEqualTo("0,1,2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trimByDefault() throws Exception {
|
||||
void trimByDefault() {
|
||||
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) {
|
||||
assertThat(array[i]).isEqualTo(("" + i));
|
||||
}
|
||||
assertTrimmedElements(value);
|
||||
assertThat(editor.getAsText()).isEqualTo("0,1,2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noTrim() throws Exception {
|
||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",",false,false);
|
||||
void noTrim() {
|
||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", false, false);
|
||||
editor.setAsText(" 0,1 , 2 ");
|
||||
Object value = editor.getValue();
|
||||
String[] array = (String[]) value;
|
||||
@@ -67,48 +59,45 @@ public class StringArrayPropertyEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withCustomSeparator() throws Exception {
|
||||
void withCustomSeparator() {
|
||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(":");
|
||||
editor.setAsText("0:1:2");
|
||||
Object value = editor.getValue();
|
||||
boolean condition = value instanceof String[];
|
||||
assertThat(condition).isTrue();
|
||||
String[] array = (String[]) value;
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
assertThat(array[i]).isEqualTo(("" + i));
|
||||
}
|
||||
assertTrimmedElements(value);
|
||||
assertThat(editor.getAsText()).isEqualTo("0:1:2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withCharsToDelete() throws Exception {
|
||||
void withCharsToDelete() {
|
||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", "\r\n", false);
|
||||
editor.setAsText("0\r,1,\n2");
|
||||
Object value = editor.getValue();
|
||||
boolean condition = value instanceof String[];
|
||||
assertThat(condition).isTrue();
|
||||
String[] array = (String[]) value;
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
assertThat(array[i]).isEqualTo(("" + i));
|
||||
}
|
||||
assertTrimmedElements(value);
|
||||
assertThat(editor.getAsText()).isEqualTo("0,1,2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withEmptyArray() throws Exception {
|
||||
void withEmptyArray() {
|
||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor();
|
||||
editor.setAsText("");
|
||||
Object value = editor.getValue();
|
||||
boolean condition = value instanceof String[];
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(((String[]) value).length).isEqualTo(0);
|
||||
assertThat(value).isInstanceOf(String[].class);
|
||||
assertThat((String[]) value).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withEmptyArrayAsNull() throws Exception {
|
||||
void withEmptyArrayAsNull() {
|
||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", true);
|
||||
editor.setAsText("");
|
||||
assertThat(editor.getValue()).isNull();
|
||||
}
|
||||
|
||||
private static void assertTrimmedElements(Object value) {
|
||||
assertThat(value).isInstanceOf(String[].class);
|
||||
String[] array = (String[]) value;
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
assertThat(array[i]).isEqualTo(("" + i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user