spockframework / spockframework/spock

Interaction on null mock object shall throw exception

Open
#2,339 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

breaking change
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

An interaction on a null object shall report an exception to the user, that the interaction does not make sense.
This shall help users to detect such interactions, which will work as intended.

This is a breaking change, because previously such interactions are silent, although probably senseless.

class TestSpec extends Specification {

  def "Interaction on null Object shall report error"() {
    given:
    Object nullObj = null

    when:
    nullObj .toString() >> ""

    then:
    def ex = thrown(IllegalArgumentException)
    ex.message == "Interaction on null object is invalid. TODO message"
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the handling for the shown nullObj.toString() >> "" interaction and its current silent behavior. Verify the change with the provided TestSpec scenario: the interaction should throw IllegalArgumentException and report the message required by the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.