Skip to content
Advertisement

Pmd rule: Too many static imports may lead to messy code in unitTest is not violated

I have a doubt, I have a class in which I’m using different static import for import constants, my issue is that I’m getting the error message: Too many static imports may lead to messy code. But in the unit test it looks like it is not a bad practice. For example in a unit test class, I’m using this import with any problem:

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;```

Conversely in my class:

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;

These imports makes me problems and I get the error message: Too many static imports may lead to messy code. I’m not pretty sure why.

I am not able to access the pmd file to figured out the real cause of this issue. Any clue?

Thanks!

Advertisement

Answer

I have used @SuppressWarnings(“PMD.TooManyStaticImports”) To avoid this issue in my class.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement