暂存提交
This commit is contained in:
@@ -4,6 +4,10 @@ import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -20,4 +24,21 @@ class GlobalExceptionHandlerTest {
|
||||
assertThat(response.getBody().code()).isEqualTo(ResultCode.BUSINESS_ERROR.code());
|
||||
assertThat(response.getBody().requestId()).isEqualTo("r1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 查询参数类型错误映射为四百而不是五百() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
Method method = GlobalExceptionHandlerTest.class.getDeclaredMethod("paging", long.class);
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
MethodArgumentTypeMismatchException exception = new MethodArgumentTypeMismatchException(
|
||||
"abc", Long.class, "page", parameter, new NumberFormatException("abc"));
|
||||
|
||||
var response = handler.handleBadRequest(exception, request);
|
||||
|
||||
assertThat(response.getStatusCode().value()).isEqualTo(400);
|
||||
assertThat(response.getBody().code()).isEqualTo(ResultCode.BAD_REQUEST.code());
|
||||
}
|
||||
|
||||
private void paging(long page) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user