0

I have a simple POJO class that has a isValid method:

public class MyClass{
    ...

    @ValidationMethod(message = "age must be ...")
    @JsonIgnore
    @SuppressWarnings("all")
    public boolean isValid() {
       return age > 10;
    }
}

I like the SonarQube to ignore this method when it checks the project.

I don't like to remove all the test coverage checks in the project, but not to check this specific line.

So I added the @SuppressWarnings("all") on top of the method, as suggested here and here. I also try to use the //NOSONAR at the end of the line:

 public boolean isValid() {
    return age > 10;//NOSONAR
}

Yet, in both cases, the SonarQube ignores the suppress requests and gives an error about

"Not Covered by tests"

:

What are we missing here? Are there more settings to do in the SonarQube itself? Are we doing it wrong?

enter image description here

riorio
  • 6,500
  • 7
  • 47
  • 100
  • See https://stackoverflow.com/questions/45365779/how-to-ignore-the-not-covered-by-tests-warning – Ori Marko Dec 04 '19 at 14:04
  • @user7294900 I don't like to remove all the test coverage checks in the project, but not to check this specific line. I'll update my question – riorio Dec 04 '19 at 14:07
  • See https://stackoverflow.com/questions/12135939/how-to-make-sonar-ignore-some-classes-for-codecoverage-metric/27133765 – Ori Marko Dec 04 '19 at 15:30

1 Answers1

0

So, following the comment of user7294900 I was able to partially success by telling sonar to completely ignore the class.

This was not our initial requirement - we wanted to just ignore the method.

We did it by adding the following <sonar.exclusions> to the pom.xml in the <properties> section, so the final result looks something like that:

 <properties>     
    <mainClass>com.example.MyApplication</mainClass>
    <sonar.exclusions>**/MyClass.java</sonar.exclusions>
</properties>
riorio
  • 6,500
  • 7
  • 47
  • 100