forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringUtilsTest.java
More file actions
43 lines (36 loc) · 1.23 KB
/
StringUtilsTest.java
File metadata and controls
43 lines (36 loc) · 1.23 KB
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
package com.examplehub.utils;
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
class StringUtilsTest {
@Test
void testBytesToString() {
byte[] bytes = {1, 2, 3, 4, 5, 0, 0, 0, 0};
assertEquals("234", StringUtils.toString(bytes, 1, 3));
}
@Test
void testCharsToString() {
char[] bytes = {'1', '2', '3', '4', '\0', '\0', '\0'};
assertEquals("234", StringUtils.toString(bytes, 1, 3));
}
@ParameterizedTest
@MethodSource
void testCapitalize(String input, String excepted) {
assertEquals(excepted, StringUtils.capitalize(input));
}
static List<Arguments> testCapitalize() {
return List.of(
Arguments.arguments("abc", "Abc"), //
Arguments.arguments("APPLE", "Apple"), //
Arguments.arguments("gooD", "Good"));
}
@ParameterizedTest
@CsvSource({"abc, Abc", "APPLE, Apple", "gooD, Good"})
void testCapitalizeCvsSource(String input, String excepted) {
assertEquals(excepted, StringUtils.capitalize(input));
}
}