WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
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
package tech.powerjob.common.utils;
 
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.junit.jupiter.api.Test;
import tech.powerjob.common.exception.PowerJobException;
 
import java.util.Collections;
import java.util.Map;
 
import static org.junit.jupiter.api.Assertions.*;
 
/**
 * CommonUtilsTest
 *
 * @author tjq
 * @since 2024/8/11
 */
class CommonUtilsTest {
 
    @Test
    void testRequireNonNull() {
 
        assertThrowsExactly(PowerJobException.class, () -> CommonUtils.requireNonNull(null, "NULL_OBJ"));
        assertThrowsExactly(PowerJobException.class, () -> CommonUtils.requireNonNull("", "EMPTY_STR"));
        assertThrowsExactly(PowerJobException.class, () -> CommonUtils.requireNonNull(Lists.newArrayList(), "EMPTY_COLLECTION"));
        assertThrowsExactly(PowerJobException.class, () -> CommonUtils.requireNonNull(Collections.emptyMap(), "EMPTY_MAP"));
 
        Map<String, Object> map = Maps.newHashMap();
        map.put("1", 1);
 
        CommonUtils.requireNonNull(1, "NORMAL");
        CommonUtils.requireNonNull("1", "NORMAL");
        CommonUtils.requireNonNull(Lists.newArrayList("1"), "NORMAL");
        CommonUtils.requireNonNull(map, "NORMAL");
 
    }
 
}