Skip to content

Commit 60b4ba3

Browse files
committed
feat: add some tests for ArgsConnectUtils.connect and StringUtil.repeat
1 parent dbbd26d commit 60b4ba3

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package net.azisaba.ryuzupluginchat.util;
2+
3+
public class StringUtil {
4+
public static String repeat(String str, int count) {
5+
StringBuilder sb = new StringBuilder(str.length() * count);
6+
for (int i = 0; i < count; i++) {
7+
sb.append(str);
8+
}
9+
return sb.toString();
10+
}
11+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package net.azisaba.ryuzupluginchat.util;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.Arguments;
6+
import org.junit.jupiter.params.provider.MethodSource;
7+
8+
import java.util.stream.Stream;
9+
10+
import static net.azisaba.ryuzupluginchat.util.StringUtil.repeat;
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
public class TestArgsConnectUtils {
14+
@ParameterizedTest(name = "[{index}] {0} => \"{1}\"")
15+
@MethodSource("provideConnectTestCases")
16+
@DisplayName("connect Test Cases")
17+
void testConnect(String[] input, String expected) {
18+
assertEquals(expected, ArgsConnectUtils.connect(input));
19+
}
20+
21+
public static Stream<Arguments> provideConnectTestCases() {
22+
return Stream.of(
23+
Arguments.of(
24+
new String[]{"Hello", "world"}, "Hello world"),
25+
Arguments.of(
26+
new String[]{"The", "quick", "brown", "fox"}, "The quick brown fox"),
27+
Arguments.of(
28+
new String[]{}, ""),
29+
Arguments.of(
30+
new String[]{"single"}, "single"),
31+
Arguments.of(
32+
new String[]{"a", "", "b"}, "a b"),
33+
Arguments.of(
34+
new String[]{" a", "b ", " c "}, " a b c "),
35+
Arguments.of(
36+
new String[]{"こんにちは", "世界"}, "こんにちは 世界"),
37+
Arguments.of(
38+
new String[]{"123", "456"}, "123 456"),
39+
Arguments.of(
40+
new String[]{"@#", "$%^", "&*()"}, "@# $%^ &*()"),
41+
Arguments.of(
42+
new String[]{repeat("a", 1000), repeat("b", 1000)},
43+
repeat("a", 1000) + " " + repeat("b", 1000)
44+
)
45+
);
46+
}
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package net.azisaba.ryuzupluginchat.util;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.Arguments;
5+
import org.junit.jupiter.params.provider.MethodSource;
6+
7+
import java.util.stream.Stream;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
public class TestStringUtil {
12+
@ParameterizedTest(name = "[{index}] repeat(\"{0}\", {1}) => \"{2}\"")
13+
@MethodSource("provideRepeatCases")
14+
void testRepeat(String input, int count, String expected) {
15+
assertEquals(expected, StringUtil.repeat(input, count));
16+
}
17+
18+
static Stream<Arguments> provideRepeatCases() {
19+
return Stream.of(
20+
Arguments.of("a", 3, "aaa"),
21+
Arguments.of("abc", 2, "abcabc"),
22+
Arguments.of("", 5, ""), // 空文字の繰り返し
23+
Arguments.of("x", 0, ""), // 0回の繰り返し
24+
Arguments.of("あ", 3, "あああ"), // Unicode 文字
25+
Arguments.of(" ", 4, " "), // 空白文字
26+
Arguments.of("ab", 1, "ab"), // 1回繰り返し
27+
Arguments.of("xy", 5, "xyxyxyxyxy") // 複数回・複数文字
28+
);
29+
}
30+
}

0 commit comments

Comments
 (0)