@Override public void init() { String rolesPropertyValue = getContext().getProperty(ROLES); if (rolesPropertyValue != null) { this.roles = StringUtils.commaDelimitedListToStringArray(rolesPropertyValue); } }
@Test public void testCommaDelimitedListToStringArraySingleString() { // Could read these from files String s = "woeirqupoiewuropqiewuorpqiwueopriquwopeiurqopwieur"; String[] sa = StringUtils.commaDelimitedListToStringArray(s); assertTrue("Found one String with no delimiters", sa.length == 1); assertTrue("Single array entry matches input String with no delimiters", sa[0].equals(s)); }
/** We expect to see the empty Strings in the output. */ @Test public void testCommaDelimitedListToStringArrayEmptyStrings() { // Could read these from files String[] sa = StringUtils.commaDelimitedListToStringArray("a,,b"); assertEquals("a,,b produces array length 3", 3, sa.length); assertTrue( "components are correct", sa[0].equals("a") && sa[1].equals("") && sa[2].equals("b")); sa = new String[] {"", "", "a", ""}; doTestCommaDelimitedListToStringArrayLegalMatch(sa); }
private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < components.length; i++) { if (i != 0) { sb.append(","); } sb.append(components[i]); } String[] sa = StringUtils.commaDelimitedListToStringArray(sb.toString()); assertTrue("String array isn't null with legal match", sa != null); assertEquals("String array length is correct with legal match", components.length, sa.length); assertTrue("Output equals input", Arrays.equals(sa, components)); }
private void doTestStringArrayReverseTransformationMatches(String[] sa) { String[] reverse = StringUtils.commaDelimitedListToStringArray(StringUtils.arrayToCommaDelimitedString(sa)); assertEquals("Reverse transformation is equal", Arrays.asList(sa), Arrays.asList(reverse)); }
@Test public void testCommaDelimitedListToStringArrayWithEmptyStringProducesEmptyArray() { String[] sa = StringUtils.commaDelimitedListToStringArray(""); assertTrue("String array isn't null with null input", sa != null); assertTrue("String array length == 0 with null input", sa.length == 0); }