can you help me how I can cover if statement by junit test in this method: This is my Method in the controller “User” : My problem is with the 2 lines of the if statment, I don’t know how i want to cover them. This is my test code for this method : Thank you in advance for your
Tag: sonarqube
How to remove duplicate cases in switch in java
I have sonarQube running but it says that there are duplicates within these lines of code. How do resolve this in a switch statement? I am just learning how unit testing in java works so any help would be great! Answer I think below solution should work for you:
Using SonarQube how would one implement a java import blacklist?
Using SonarQube (version 3.0) I am trying to implement a blacklist of java libraries. For example I’d like for SonarQube to generate a code smell for any java file that contains an import for org.apache.lang.StringUtils I did find this rule: “Track uses of disallowed dependencies” however as previously stated I want to focus on the java file import statements themselves.
How to group cases in a switch statment? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago. Improve this question I currently have 31 cases in my Java switch statement. Originally, there were 30 and I have now added one more.
Searching for issues with Sonarcloud API returns none even though they exist
I am trying to get all the sonar report issues from a branch of a private Sonarcloud project. I do this with the following REST call: If I enter this call normally in the webbrowser or with a postman call, I get this response: So I get the full report with the 1 sonar issue, like it’s shown in the
Sonar: Possible null pointer dereference due to return value of called method
I am getting issue from Sonar: “Style – Possible null pointer dereference due to return value of called method. findbugs:NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE. the issue is on lockUntil.after(new Date()); I’ve tried to change this issue line with or But it introduces other issues. Can anyone please guide? Answer Assuming that new Date() will never return null should be a valid assumption. My guess
Sonar Cube “null pointer exception could be thrown” : False positive?
I have a bug raised by sonar cube on following code : The bug is raised at log.info statement as it suggests to check request for NULL before using. But my doubt is in case I check it for null and if it is actually null, then I would like it to goto catch exception block, which anyhow it will
Singleton writes a field in unsynchronized manner
I am getting : Singleton class writes to a field in an unsynchronized manner at 4-5 places in Springboot code while scanning through SonarQube. Now, I am trying to understand how can I make this warning go away? Is there a general fix for this error One example is below : Answer never ever expose a mutable field directly, least
Kotlin, Java 8 and Sonar coverage showing as 0
I have a kotlin project using Java 8 and I use Sonar to measure code coverage I am using the latest version of Sonar and noticed the coverage has gone down due to changes in the openjdk. My tests are using Mockito and PowerMockito. Some tests are failing due to reflection errors. When I add the following jvm args –
Checkmarx – How to validate and sanitize HttpServletRequest .getInputStream to pass checkmarx scan
Following are checkmarx issue details Unrestricted File Upload Source Object : req (Line No – 39) target Object : getInputStream (Line No -41) request objects get highlighted in checkmarx tool – How do I properly validate, filter, escape, and/or encode user-controllable input to pass a Checkmarx scan? Answer This worked for me – checkmarx pass this high vulnerability I used