Search in sources :

Example 1 with StringJoiner

use of java8.util.StringJoiner in project streamsupport by stefan-zobel.

the class MergeTest method testEmptyOther.

public void testEmptyOther() {
    fixesStream().forEach(fixes -> {
        StringJoiner sj = new StringJoiner(",", fixes.pre0, fixes.suf0);
        StringJoiner other = new StringJoiner(",", fixes.pre1, fixes.suf1);
        RefStreams.of("a", "b", "c").forEachOrdered(sj::add);
        sj.merge(other);
        assertEquals(sj.toString(), fixes.pre0 + "a,b,c" + fixes.suf0);
        other.setEmptyValue("EMPTY");
        sj.merge(other);
        assertEquals(sj.toString(), fixes.pre0 + "a,b,c" + fixes.suf0);
    });
}
Also used : StringJoiner(java8.util.StringJoiner)

Example 2 with StringJoiner

use of java8.util.StringJoiner in project streamsupport by stefan-zobel.

the class MergeTest method testDelimiter.

public void testDelimiter() {
    fixesStream().forEach(fixes -> {
        StringJoiner sj = new StringJoiner(",", fixes.pre0, fixes.suf0);
        StringJoiner other = new StringJoiner(":", fixes.pre1, fixes.suf1);
        RefStreams.of("a", "b", "c").forEachOrdered(sj::add);
        RefStreams.of("d", "e", "f").forEachOrdered(other::add);
        sj.merge(other);
        assertEquals(sj.toString(), fixes.pre0 + "a,b,c,d:e:f" + fixes.suf0);
    });
}
Also used : StringJoiner(java8.util.StringJoiner)

Example 3 with StringJoiner

use of java8.util.StringJoiner in project streamsupport by stefan-zobel.

the class MergeTest method testNull.

@Test(expectedExceptions = { NullPointerException.class })
public void testNull() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    sj.merge(null);
}
Also used : StringJoiner(java8.util.StringJoiner) Test(org.testng.annotations.Test)

Example 4 with StringJoiner

use of java8.util.StringJoiner in project streamsupport by stefan-zobel.

the class MergeTest method testEmptyThis.

public void testEmptyThis() {
    fixesStream().forEach(fixes -> {
        StringJoiner sj = new StringJoiner(",", fixes.pre0, fixes.suf0);
        StringJoiner other = new StringJoiner(":", fixes.pre1, fixes.suf1);
        RefStreams.of("d", "e", "f").forEachOrdered(other::add);
        sj.merge(other);
        assertEquals(sj.toString(), fixes.pre0 + "d:e:f" + fixes.suf0);
        sj = new StringJoiner(",", fixes.pre0, fixes.suf0).setEmptyValue("EMPTY");
        assertEquals(sj.toString(), "EMPTY");
        sj.merge(other);
        assertEquals(sj.toString(), fixes.pre0 + "d:e:f" + fixes.suf0);
    });
}
Also used : StringJoiner(java8.util.StringJoiner)

Example 5 with StringJoiner

use of java8.util.StringJoiner in project streamsupport by stefan-zobel.

the class StringJoinerTest method addString.

public void addString() {
    StringJoiner sj = new StringJoiner(DASH);
    sj.add(ONE);
    assertEquals(sj.toString(), ONE);
    sj = new StringJoiner(DASH, "{", "}");
    sj.add(ONE);
    assertEquals(sj.toString(), "{" + ONE + "}");
    sj.add(TWO);
    assertEquals(sj.toString(), "{" + ONE + DASH + TWO + "}");
}
Also used : StringJoiner(java8.util.StringJoiner)

Aggregations

StringJoiner (java8.util.StringJoiner)22 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)2