Commit 3d7fdff2 authored by yanzg's avatar yanzg

将源码打包进jar包

parent 8f0cae2f
...@@ -40,11 +40,10 @@ public class ExceptionHelper { ...@@ -40,11 +40,10 @@ public class ExceptionHelper {
* @param end 结束位置 * @param end 结束位置
* @param length 总长度 * @param length 总长度
* @param str 结果 * @param str 结果
* @throws Exception 抛出异常
*/ */
public static void subStringException(String local, int start, int end, int length, String str) throws Exception { public static void subStringException(String local, int start, int end, int length, String str) {
String exception = local + "/n" + "开始:" + start + " 结束:" + end + "总长:" + length + "/n" + str; String exception = local + "/n" + "开始:" + start + " 结束:" + end + "总长:" + length + "/n" + str;
throw new Exception(exception); throw new CodeException(exception);
} }
......
package helper; package helper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.CodeTargetException;
import com.yanzuoguang.util.exception.ExceptionHelper; 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; import org.junit.Test;
public class TestExceptionHelper { public class TestExceptionHelper {
...@@ -9,4 +14,42 @@ public class TestExceptionHelper { ...@@ -9,4 +14,42 @@ public class TestExceptionHelper {
public void testException() { public void testException() {
ExceptionHelper.handleException(TestExceptionHelper.class, new Exception("错误"), "消息"); 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, "字符");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment