PropertyValidator { static String[] convertToStringArray(Object o) { String[] result; if (o == null) { result = new String[0]; } else if (o instanceof List) { List list = (List) o; result = new String[list.size()]; for (int i = 0; i < list.size(); i++) { result[i] = String.valueOf(list.get(i)); } } else if (o.getClass().isArray()) { Object[] array = (Object[]) o; result = new String[array.length]; for (int i = 0; i < array.length; i++) { result[i] = String.valueOf(array[i]); } } else { result = new String[1]; result[0] = String.valueOf(o); } return result; }    }
@Test public void testConvertToStringArray() throws Exception { assertThat(convertToStringArray(null), Is.<Object>is(new String[0])); assertThat(convertToStringArray("test"), Is.<Object>is(new String[]{"test"})); assertThat(convertToStringArray(new String[]{"test"}), Is.<Object>is(new String[]{"test"})); assertThat(convertToStringArray(singletonList("test")), Is.<Object>is(new String[]{"test"})); assertThat(convertToStringArray(new Vector<>(singletonList("test"))), Is.<Object>is(new String[]{"test"})); assertThat(convertToStringArray(1), Is.<Object>is(new String[]{"1"})); }