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
44
45
46
47
48
49
50
51
52
53
54
55
package helper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.CodeTargetException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.vo.ResponseResult;
import org.junit.Assert;
import org.junit.Test;
public class TestExceptionHelper {
@Test
public void testException() {
ExceptionHelper.handleException(TestExceptionHelper.class, new Exception("错误"), "消息");
}
@Test
public void testGetErrorCodeException() {
ResponseResult<?> err = ExceptionHelper.getError(new CodeException("颜佐光", true));
String errResult = JsonHelper.serialize(err);
Assert.assertEquals("{\"code\":\"99\",\"message\":\"颜佐光\"}", errResult);
err = ExceptionHelper.getError(new CodeException("05", "颜佐光", true));
errResult = JsonHelper.serialize(err);
Assert.assertEquals("{\"code\":\"05\",\"message\":\"颜佐光\"}", errResult);
err = ExceptionHelper.getError(new CodeException("05", "颜佐光", true));
errResult = JsonHelper.serialize(err);
Assert.assertEquals("{\"code\":\"05\",\"message\":\"颜佐光\"}", errResult);
}
@Test
public void testGetErrorCodeTargetException() {
ResponseResult<?> err = ExceptionHelper.getError(new CodeTargetException("颜佐光", true));
String errResult = JsonHelper.serialize(err);
Assert.assertEquals("{\"code\":\"99\",\"message\":\"颜佐光\",\"target\":true}", errResult);
err = ExceptionHelper.getError(new CodeTargetException("05", "颜佐光", true));
errResult = JsonHelper.serialize(err);
Assert.assertEquals("{\"code\":\"05\",\"message\":\"颜佐光\",\"target\":true}", errResult);
}
@Test
public void testGetErrorException() {
ResponseResult<?> err = ExceptionHelper.getError(new Exception("颜佐光"));
String errResult = JsonHelper.serialize(err);
Assert.assertEquals("{\"code\":\"99\",\"message\":\"颜佐光\"}", errResult);
}
@Test
public void testSubStrException() {
ExceptionHelper.subStringException("字符", 0, 10, 2, "字符");
}
}