IntelliJ IDEA & Spock: Groovy Pointless Arithmetic

Maybe this is just plain stupid but there is a simple workaround for the warning 0 * report.addError can be replaced by 0 in the following test (in IDEA):

def "does not report step error or failure when it succeeds" () {
  Result result = Mock (Result)
  result.error >> null

  when:
    uat.step (stepStub ())
    uat.result (result)

  then:
    0 * report.addError (_)
    0 * report.addFailure (_)
}

My solution so far was to add an @SuppressWarnings(["GroovyPointlessArithmetic"]) to the test class. But there is a simpler solution without disabling the warning. I can simply write

def "does not report step error or failure when it succeeds" () {
  Result result = Mock (Result)
  result.error >> null

  when:
    uat.step (stepStub ())
    uat.result (result)

  then:
    (0) * report.addError (_)
    (0) * report.addFailure (_)
}

to remove the warning. See the difference? I have replaced the 0 with (0) and the warning goes away. :-)

Advertisements

4 thoughts on “IntelliJ IDEA & Spock: Groovy Pointless Arithmetic

    • Disabling it feels like cheating :-)

      At some point I enabled all inspections just to see what would come up. At the beginning I disabled those that came up too often. I didn’t disable anything for while now.

      But i guess for this one it makes sense, never seen it outside of a spock test.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s