我有一个疑问,我有一个类,我在其中使用不同的静态导入来导入常量,我的问题是我收到错误消息:Too many static imports may lead to messy code
. 但在单元测试中,看起来这不是一个坏习惯。例如在一个单元测试类中,我使用这个导入有任何问题:
import static com.rccl.middleware.kidsclub.engine.web.controller.KidController.KID_FIND_PATH;
import static com.rccl.middleware.kidsclub.engine.web.controller.KidController.KID_LIST_PATH;
import static com.rccl.middleware.kidsclub.engine.web.controller.KidController.KID_PATH;
import static com.rccl.middleware.kidsclub.engine.web.controller.KidController.KID_REGISTER_ALL_PATH;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.times;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;```
相反,在我的课堂上:
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
这些导入给我带来了麻烦,我收到错误消息:太多静态导入可能导致代码混乱。我不太清楚为什么。
我无法访问 pmd 文件来找出这个问题的真正原因。有什么线索吗?
谢谢!