Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
3d7fdff2
Commit
3d7fdff2
authored
May 20, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将源码打包进jar包
parent
8f0cae2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
3 deletions
+45
-3
ExceptionHelper.java
.../java/com/yanzuoguang/util/exception/ExceptionHelper.java
+2
-3
TestExceptionHelper.java
yzg-util-base/src/test/java/helper/TestExceptionHelper.java
+43
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/exception/ExceptionHelper.java
View file @
3d7fdff2
...
...
@@ -40,11 +40,10 @@ public class ExceptionHelper {
* @param end 结束位置
* @param length 总长度
* @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
;
throw
new
Exception
(
exception
);
throw
new
Code
Exception
(
exception
);
}
...
...
yzg-util-base/src/test/java/helper/TestExceptionHelper.java
View file @
3d7fdff2
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
{
...
...
@@ -9,4 +14,42 @@ public class TestExceptionHelper {
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
,
"字符"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment