Fix joinOn
This commit is contained in:
2 files changed
+38
-1
No files matched your search
@@ -626,12 +626,12 @@ public final class CollectionUtil {
|
||||
String delimiter) {
|
||||
boolean first = true;
|
||||
for (T t : iterable) {
|
||||
appendItem.accept(sb, t);
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append(delimiter);
|
||||
}
|
||||
appendItem.accept(sb, t);
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.util;
|
||||
|
||||
import static net.sourceforge.pmd.util.CollectionUtil.listOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.document.Chars;
|
||||
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class CollectionUtilTest {
|
||||
|
||||
@Test
|
||||
public void testJoinOn() {
|
||||
testJoinOn(listOf("a", "b", "c"), ".",
|
||||
"a.b.c");
|
||||
testJoinOn(Collections.emptyList(), ".",
|
||||
"");
|
||||
}
|
||||
|
||||
private void testJoinOn(List<String> toJoin, String delimiter, String expected) {
|
||||
String actual = CollectionUtil.joinCharsIntoStringBuilder(
|
||||
CollectionUtil.map(toJoin, Chars::wrap),
|
||||
delimiter
|
||||
).toString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user