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
d00a44f0
Commit
d00a44f0
authored
Aug 13, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
升级新版本
parent
be481034
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
8 deletions
+110
-8
ResponseResult.java
...src/main/java/com/yanzuoguang/util/vo/ResponseResult.java
+18
-8
TestException.java
yzg-util-base/src/test/java/base/TestException.java
+92
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/ResponseResult.java
View file @
d00a44f0
...
...
@@ -3,6 +3,7 @@ package com.yanzuoguang.util.vo;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeTargetException
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.exception.RuntimeCodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
@@ -243,7 +244,7 @@ public class ResponseResult<T> extends BaseVo {
}
}
public
static
final
ResponseResult
OK
=
new
ResponseResult
();
public
static
final
ResponseResult
<
Object
>
OK
=
new
ResponseResult
();
/**
* 处理错误
...
...
@@ -251,7 +252,7 @@ public class ResponseResult<T> extends BaseVo {
* @param target 错误源对象
* @return 处理的错误
*/
public
static
final
ResponseResult
error
(
Object
target
)
{
public
static
final
ResponseResult
<
Object
>
error
(
Object
target
)
{
return
error
(
ResultConstants
.
UNKNOW_ERROR
,
"未知异常"
,
target
);
}
...
...
@@ -262,7 +263,7 @@ public class ResponseResult<T> extends BaseVo {
* @param message 错误消息
* @return 处理的错误
*/
public
static
final
ResponseResult
error
(
String
code
,
String
message
)
{
public
static
final
ResponseResult
<
Object
>
error
(
String
code
,
String
message
)
{
return
error
(
code
,
message
,
null
);
}
...
...
@@ -273,8 +274,18 @@ public class ResponseResult<T> extends BaseVo {
* @param target 错误标记
* @return 处理的错误
*/
public
static
final
ResponseResult
error
(
String
message
,
Object
target
)
{
return
error
(
ResultConstants
.
UNKNOW_ERROR
,
message
,
null
);
public
static
final
ResponseResult
<
Object
>
error
(
String
message
,
Object
target
)
{
return
error
(
ResultConstants
.
UNKNOW_ERROR
,
message
,
target
);
}
/**
* 处理错误
*
* @param ex 错误消息
* @return 处理的错误
*/
public
static
final
ResponseResult
error
(
Exception
ex
)
{
return
ExceptionHelper
.
getError
(
ex
);
}
/**
...
...
@@ -285,9 +296,8 @@ public class ResponseResult<T> extends BaseVo {
* @param target 错误标记
* @return 处理的错误
*/
public
static
final
ResponseResult
error
(
String
code
,
String
message
,
Object
target
)
{
ResponseResult
ret
=
new
ResponseResult
(
code
,
message
,
null
,
target
);
return
ret
;
public
static
final
ResponseResult
<
Object
>
error
(
String
code
,
String
message
,
Object
target
)
{
return
new
ResponseResult
<>(
code
,
message
,
null
,
target
);
}
/**
...
...
yzg-util-base/src/test/java/base/TestException.java
0 → 100644
View file @
d00a44f0
package
base
;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeTargetException
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.exception.RuntimeCodeException
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
TestException
{
@Test
public
void
testCodeException
()
{
CodeException
codeException
=
new
CodeException
(
"05"
,
"message"
,
"target"
);
ResponseResult
<?>
error
=
ExceptionHelper
.
getError
(
codeException
);
Assert
.
assertEquals
(
codeException
.
getCode
(),
error
.
getCode
());
Assert
.
assertEquals
(
codeException
.
getMessage
(),
error
.
getMessage
());
Assert
.
assertNull
(
error
.
getTarget
());
try
{
error
.
check
();
}
catch
(
CodeException
ex
)
{
Assert
.
assertEquals
(
ex
.
getClass
(),
CodeException
.
class
);
Assert
.
assertEquals
(
codeException
.
getCode
(),
ex
.
getCode
());
Assert
.
assertEquals
(
codeException
.
getMessage
(),
ex
.
getMessage
());
Assert
.
assertNull
(
ex
.
getTarget
());
}
}
@Test
public
void
testCodeTargetException
()
{
CodeTargetException
codeException
=
new
CodeTargetException
(
"05"
,
"message"
,
"target"
);
ResponseResult
<?>
error
=
ExceptionHelper
.
getError
(
codeException
);
Assert
.
assertEquals
(
codeException
.
getCode
(),
error
.
getCode
());
Assert
.
assertEquals
(
codeException
.
getMessage
(),
error
.
getMessage
());
Assert
.
assertEquals
(
codeException
.
getTarget
(),
error
.
getTarget
());
try
{
error
.
check
();
}
catch
(
CodeTargetException
ex
)
{
Assert
.
assertEquals
(
ex
.
getClass
(),
CodeTargetException
.
class
);
Assert
.
assertEquals
(
codeException
.
getCode
(),
ex
.
getCode
());
Assert
.
assertEquals
(
codeException
.
getMessage
(),
ex
.
getMessage
());
Assert
.
assertEquals
(
codeException
.
getTarget
(),
ex
.
getTarget
());
}
}
@Test
public
void
testRuntimeCodeException
()
{
RuntimeCodeException
codeException
=
new
RuntimeCodeException
(
"05"
,
"message"
,
"target"
);
ResponseResult
<?>
error
=
ExceptionHelper
.
getError
(
codeException
);
Assert
.
assertEquals
(
codeException
.
getCode
(),
error
.
getCode
());
Assert
.
assertEquals
(
codeException
.
getMessage
(),
error
.
getMessage
());
Assert
.
assertNull
(
error
.
getTarget
());
try
{
error
.
check
();
}
catch
(
RuntimeCodeException
ex
)
{
Assert
.
assertEquals
(
ex
.
getClass
(),
RuntimeCodeException
.
class
);
Assert
.
assertEquals
(
codeException
.
getCode
(),
ex
.
getCode
());
Assert
.
assertEquals
(
codeException
.
getMessage
(),
ex
.
getMessage
());
Assert
.
assertNull
(
ex
.
getTarget
());
}
}
@Test
public
void
testException
()
{
Exception
codeException
=
new
Exception
(
"message"
);
ResponseResult
<?>
error
=
ExceptionHelper
.
getError
(
codeException
);
Assert
.
assertEquals
(
ResultConstants
.
UNKNOW_ERROR
,
error
.
getCode
());
Assert
.
assertEquals
(
codeException
.
getMessage
(),
error
.
getMessage
());
Assert
.
assertNull
(
error
.
getTarget
());
try
{
error
.
check
();
}
catch
(
RuntimeCodeException
ex
)
{
Assert
.
assertEquals
(
ex
.
getClass
(),
RuntimeCodeException
.
class
);
Assert
.
assertEquals
(
ResultConstants
.
UNKNOW_ERROR
,
ex
.
getCode
());
Assert
.
assertEquals
(
codeException
.
getMessage
(),
ex
.
getMessage
());
Assert
.
assertNull
(
ex
.
getTarget
());
}
}
}
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