ParameterUtils { public static List<String> splitParams(String parameterString) { ArrayList<String> params = new ArrayList<>(); Matcher m = WHITESPACE_IF_NOT_QUOTED.matcher(parameterString); while (m.find()) { if (m.group(1) != null) { params.add(m.group(1)); } else { params.add(m.group(2)); } } return params; } private  ParameterUtils(); static List<String> splitParams(String parameterString);  }
@Test public void mixedParams() { List<String> splitParams = ParameterUtils.splitParams(QUOTED_PARAM_WITH_WHITESPACE.concat(" ").concat(PARAM_WITHOUT_WHITESPACE).concat(" ").concat(QUOTED_PARAM_WITH_WHITESPACE).concat(" ").concat(QUOTED_PARAM_WITH_WHITESPACE).concat(" ").concat(PARAM_WITHOUT_WHITESPACE).concat(" ").concat(QUOTED_PARAM_WITH_WHITESPACE)); Assert.assertArrayEquals(new String[] {PARAM_WITH_WHITESPACE, PARAM_WITHOUT_WHITESPACE, PARAM_WITH_WHITESPACE, PARAM_WITH_WHITESPACE, PARAM_WITHOUT_WHITESPACE, PARAM_WITH_WHITESPACE}, splitParams.toArray(new String[0])); }
@Test public void singleParamWithWS() { List<String> splitParams = ParameterUtils.splitParams(QUOTED_PARAM_WITH_WHITESPACE); Assert.assertArrayEquals(new String[] {PARAM_WITH_WHITESPACE}, splitParams.toArray(new String[0])); }
@Test public void singleParamWithoutWS() { List<String> splitParams = ParameterUtils.splitParams(PARAM_WITHOUT_WHITESPACE); Assert.assertArrayEquals(new String[] {PARAM_WITHOUT_WHITESPACE}, splitParams.toArray(new String[0])); }
@Test public void onlyParamsWithWhitespaces() { List<String> splitParams = ParameterUtils.splitParams(QUOTED_PARAM_WITH_WHITESPACE.concat(" ").concat(QUOTED_PARAM_WITH_WHITESPACE).concat(QUOTED_PARAM_WITH_WHITESPACE)); Assert.assertArrayEquals(new String[] {PARAM_WITH_WHITESPACE, PARAM_WITH_WHITESPACE, PARAM_WITH_WHITESPACE}, splitParams.toArray(new String[0])); }
@Test public void onlyParamsWithoutWhitespaces() { List<String> splitParams = ParameterUtils.splitParams(PARAM_WITHOUT_WHITESPACE.concat(" ").concat(PARAM_WITHOUT_WHITESPACE).concat(" ").concat(PARAM_WITHOUT_WHITESPACE)); Assert.assertArrayEquals(new String[] {PARAM_WITHOUT_WHITESPACE, PARAM_WITHOUT_WHITESPACE, PARAM_WITHOUT_WHITESPACE}, splitParams.toArray(new String[0])); }