You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.7 KiB
89 lines
2.7 KiB
package com.ruoyi.common.utils;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.Collection;
|
|
import java.util.Arrays;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class StringUtilsTest {
|
|
|
|
@Test
|
|
void testIsEmpty() {
|
|
assertTrue(StringUtils.isEmpty((String) null));
|
|
assertTrue(StringUtils.isEmpty(""));
|
|
assertTrue(StringUtils.isEmpty(" ")); // isEmpty 会 trim 空格
|
|
assertFalse(StringUtils.isEmpty("test"));
|
|
}
|
|
|
|
@Test
|
|
void testIsNotEmpty() {
|
|
assertFalse(StringUtils.isNotEmpty((String) null));
|
|
assertFalse(StringUtils.isNotEmpty(""));
|
|
assertFalse(StringUtils.isNotEmpty(" ")); // isNotEmpty 会 trim 空格
|
|
assertTrue(StringUtils.isNotEmpty("test"));
|
|
}
|
|
|
|
@Test
|
|
void testIsNull() {
|
|
assertTrue(StringUtils.isNull(null));
|
|
assertFalse(StringUtils.isNull(""));
|
|
assertFalse(StringUtils.isNull("test"));
|
|
}
|
|
|
|
@Test
|
|
void testIsNotEmpty_Collection() {
|
|
Collection<String> emptyList = Arrays.asList();
|
|
Collection<String> nonEmptyList = Arrays.asList("item1", "item2");
|
|
|
|
assertFalse(StringUtils.isNotEmpty(emptyList));
|
|
assertTrue(StringUtils.isNotEmpty(nonEmptyList));
|
|
}
|
|
|
|
@Test
|
|
void testNvl() {
|
|
assertEquals("default", StringUtils.nvl(null, "default"));
|
|
assertEquals("value", StringUtils.nvl("value", "default"));
|
|
assertEquals("", StringUtils.nvl("", "default"));
|
|
}
|
|
|
|
@Test
|
|
void testEquals() {
|
|
assertTrue(StringUtils.equals("test", "test"));
|
|
assertFalse(StringUtils.equals("test1", "test2"));
|
|
assertFalse(StringUtils.equals(null, "test"));
|
|
assertFalse(StringUtils.equals("test", null));
|
|
assertTrue(StringUtils.equals(null, null));
|
|
}
|
|
|
|
@Test
|
|
void testContains() {
|
|
assertTrue(StringUtils.contains("hello world", "world"));
|
|
assertFalse(StringUtils.contains("hello world", "test"));
|
|
assertFalse(StringUtils.contains(null, "test"));
|
|
assertFalse(StringUtils.contains("test", null));
|
|
}
|
|
|
|
@Test
|
|
void testStartsWith() {
|
|
assertTrue(StringUtils.startsWith("hello", "hel"));
|
|
assertFalse(StringUtils.startsWith("hello", "world"));
|
|
assertFalse(StringUtils.startsWith(null, "test"));
|
|
}
|
|
|
|
@Test
|
|
void testSubstring() {
|
|
assertEquals("ell", StringUtils.substring("hello", 1, 4));
|
|
assertEquals("hello", StringUtils.substring("hello", 0));
|
|
assertEquals("", StringUtils.substring(null, 0));
|
|
}
|
|
|
|
@Test
|
|
void testTrim() {
|
|
assertEquals("test", StringUtils.trim(" test "));
|
|
assertEquals("", StringUtils.trim(" "));
|
|
assertEquals("", StringUtils.trim(null));
|
|
}
|
|
}
|