wangzhibo
2026-08-16 ae6f40460dcd56af6c5f60ba52c883854c3bac55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package nodomain.freeyourgadget.gadgetbridge.test;
 
import org.junit.Test;
 
import java.nio.charset.StandardCharsets;
 
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
 
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
 
public class StringUtilsTest extends TestBase {
    private static final String SEP = ":";
    private static final String E1 = "e1";
    private static final String E2 = "e2";
    private static final String E3 = "e3";
 
    @Test
    public void testJoinNull() {
        StringBuilder result = StringUtils.join(SEP, (String[]) null);
        assertEquals("", result.toString());
    }
 
    @Test
    public void testJoinNullElement() {
        StringBuilder result = StringUtils.join(SEP, (String) null);
        assertEquals("", result.toString());
    }
 
    @Test
    public void testJoinSingleElement() {
        StringBuilder result = StringUtils.join(SEP, E1);
        assertEquals(E1, result.toString());
    }
 
    @Test
    public void testJoinSingleAndNullElement() {
        StringBuilder result = StringUtils.join(SEP, E1, null);
        assertEquals(E1, result.toString());
    }
 
    @Test
    public void testJoinTwoElements() {
        StringBuilder result = StringUtils.join(SEP, E1, E2);
        assertEquals(E1 + SEP + E2, result.toString());
    }
 
    @Test
    public void testJoinTwoElementsAndNull() {
        StringBuilder result = StringUtils.join(SEP, E1, null, E2);
        assertEquals(E1 + SEP + E2, result.toString());
    }
 
    @Test
    public void testJoinThreeElements() {
        StringBuilder result = StringUtils.join(SEP, E1, E2, E3);
        assertEquals(E1 + SEP + E2 + SEP + E3, result.toString());
    }
 
    @Test
    public void testUntilNullTerminator() {
        assertNull(StringUtils.untilNullTerminator("Hello, World!".getBytes(StandardCharsets.UTF_8), 7));
        assertNull(StringUtils.untilNullTerminator("Hello, World!".getBytes(StandardCharsets.UTF_8), 99));
        assertEquals("Hello, World!", StringUtils.untilNullTerminator("Hello, World!\0Another String".getBytes(StandardCharsets.UTF_8), 0));
        assertEquals("World!", StringUtils.untilNullTerminator("Hello, World!\0Another String".getBytes(StandardCharsets.UTF_8), 7));
        assertEquals("", StringUtils.untilNullTerminator("Hello, World!\0Another String".getBytes(StandardCharsets.UTF_8), 13));
        assertNull(StringUtils.untilNullTerminator("Hello, World!\0Another String".getBytes(StandardCharsets.UTF_8), 14));
        assertNull(StringUtils.untilNullTerminator("Hello, World!\0Another String".getBytes(StandardCharsets.UTF_8), 99));
    }
}