Add test cases for StringUtil. (#10074)
Motivation: StringUtil needs more test cases. Modification: Add several test cases for StringUtil. Result: Improve test coverage slightly.
This commit is contained in:
parent
aec2c8e4e0
commit
2559e163ca
@ -22,6 +22,9 @@ import java.util.Collections;
|
||||
|
||||
import static io.netty.util.internal.StringUtil.NEWLINE;
|
||||
import static io.netty.util.internal.StringUtil.commonSuffixOfLength;
|
||||
import static io.netty.util.internal.StringUtil.indexOfWhiteSpace;
|
||||
import static io.netty.util.internal.StringUtil.indexOfNonWhiteSpace;
|
||||
import static io.netty.util.internal.StringUtil.isNullOrEmpty;
|
||||
import static io.netty.util.internal.StringUtil.simpleClassName;
|
||||
import static io.netty.util.internal.StringUtil.substringAfter;
|
||||
import static io.netty.util.internal.StringUtil.toHexString;
|
||||
@ -549,4 +552,43 @@ public class StringUtilTest {
|
||||
StringUtil.join(",", Arrays.asList("a", "b", "c", null, "d")).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNullOrEmpty() {
|
||||
assertTrue(isNullOrEmpty(null));
|
||||
assertTrue(isNullOrEmpty(""));
|
||||
assertTrue(isNullOrEmpty(StringUtil.EMPTY_STRING));
|
||||
assertFalse(isNullOrEmpty(" "));
|
||||
assertFalse(isNullOrEmpty("\t"));
|
||||
assertFalse(isNullOrEmpty("\n"));
|
||||
assertFalse(isNullOrEmpty("foo"));
|
||||
assertFalse(isNullOrEmpty(NEWLINE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfWhiteSpace() {
|
||||
assertEquals(-1, indexOfWhiteSpace("", 0));
|
||||
assertEquals(0, indexOfWhiteSpace(" ", 0));
|
||||
assertEquals(-1, indexOfWhiteSpace(" ", 1));
|
||||
assertEquals(0, indexOfWhiteSpace("\n", 0));
|
||||
assertEquals(-1, indexOfWhiteSpace("\n", 1));
|
||||
assertEquals(0, indexOfWhiteSpace("\t", 0));
|
||||
assertEquals(-1, indexOfWhiteSpace("\t", 1));
|
||||
assertEquals(3, indexOfWhiteSpace("foo\r\nbar", 1));
|
||||
assertEquals(-1, indexOfWhiteSpace("foo\r\nbar", 10));
|
||||
assertEquals(7, indexOfWhiteSpace("foo\tbar\r\n", 6));
|
||||
assertEquals(-1, indexOfWhiteSpace("foo\tbar\r\n", Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOfNonWhiteSpace() {
|
||||
assertEquals(-1, indexOfNonWhiteSpace("", 0));
|
||||
assertEquals(-1, indexOfNonWhiteSpace(" ", 0));
|
||||
assertEquals(-1, indexOfNonWhiteSpace(" \t", 0));
|
||||
assertEquals(-1, indexOfNonWhiteSpace(" \t\r\n", 0));
|
||||
assertEquals(2, indexOfNonWhiteSpace(" \tfoo\r\n", 0));
|
||||
assertEquals(2, indexOfNonWhiteSpace(" \tfoo\r\n", 1));
|
||||
assertEquals(4, indexOfNonWhiteSpace(" \tfoo\r\n", 4));
|
||||
assertEquals(-1, indexOfNonWhiteSpace(" \tfoo\r\n", 10));
|
||||
assertEquals(-1, indexOfNonWhiteSpace(" \tfoo\r\n", Integer.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user