@Override public void run() { int count = 0; for (int i = 0; i < TINY_REPEAT_COUNT; i++) { final String[] strings = StringUtils.split(TINY_STRING, ' '); count += strings.length; } if (count != 2 * TINY_REPEAT_COUNT) { throw new RuntimeException("Check test condition"); } }
@Override public void run() { int count = 0; for (int i = 0; i < SHORT_REPEAT_COUNT; i++) { final String[] strings = StringUtils.split(SHORT_STRING, ' '); count += strings.length; } if (count != 9 * SHORT_REPEAT_COUNT) { throw new RuntimeException("Check test condition"); } }
@Override public void run() { final String[] strings = StringUtils.split(LONG_STRING, ' '); if (strings.length != LONG_WORDS_COUNT + 1) { // "+ 1" for the last closing space throw new RuntimeException("Check test condition"); } }
private static String generateLongString(int wordsCount) { StringBuilder builder = new StringBuilder(); String[] words = StringUtils.split(SHORT_STRING, ' '); for (int i = 0; i < wordsCount; i++) { builder.append(words[i % words.length]).append(' '); } return builder.toString(); }
@Test public void testSplit() throws Exception { assertArrayEquals(ss("John", "Doe"), StringUtils.split("John Doe", ' ')); assertArrayEquals(ss("John", "", "Doe", ""), StringUtils.split("John Doe ", ' ')); assertArrayEquals(ss("", "John", "Doe", ""), StringUtils.split(" John Doe ", ' ')); assertArrayEquals(ss("John", "Christoph", "Doe"), StringUtils.split("John Christoph Doe", ' ')); assertArrayEquals(ss("John", "", "", "Doe"), StringUtils.split("John,,,Doe", ',')); assertArrayEquals(ss("John", "Doe", ""), StringUtils.split("John Doe ", ' ')); assertArrayEquals(ss("John", "", "", ""), StringUtils.split("John,,,", ',')); }