微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sonarlint 消息的描述部分可以关闭吗?

如何解决sonarlint 消息的描述部分可以关闭吗?

我正在使用 gradle 插件 name.remal.sonarlint 在 CI 管道中运行 sonarlint。 sonarlint 输出的消息由 3 部分组成:

[rank 5] [java:S6068] /builds/xxxxx/XxxxTest.java:23:39
  Call to Mockito method "verify","when" or "given" should be simplified
  Mockito provides argument matchers for flexibly stubbing or verifying method calls.
  Mockito.verify(),Mockito.when(),Stubber.when() and BDDMockito.given() each have overloads with
  and without argument matchers.
  However,the default matching behavior (i.e. without argument matchers) uses equals(). If only
  the matcher org.mockito.ArgumentMatchers.eq() is used,the call is equivalent to the call without
  matchers,i.e. the eq() is not necessary and can be omitted. The resulting code is shorter and
  easier to read.
  Noncompliant Code Example
  @Test
  public void mytest() {
    given(foo.bar(eq(v1),eq(v2),eq(v3))).willReturn(null);   // Noncompliant
    when(foo.baz(eq(v4),eq(v5))).thenReturn("foo");   // Noncompliant
    doThrow(new RuntimeException()).when(foo).quux(eq(42));    // Noncompliant
    verify(foo).bar(eq(v1),eq(v3));   // Noncompliant
  }
  Compliant Solution
  @Test
  public void mytest() {
    given(foo.bar(v1,v2,v3)).willReturn(null);
    when(foo.baz(v4,v5)).thenReturn("foo");
    doThrow(new RuntimeException()).when(foo).quux(42);
    verify(foo).bar(v1,v3);
  }
  See
  * Mockito documentation
    <https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#argument_matchers>
    - argument matchers
  * {rule:java:S6073} - Mockito argument matchers should be used on all parameters

如何将 sonarlint 配置为仅生成前 2 个部分?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。