Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

withObjectSpied call real method instead of stubbed #468

Copy link
Copy link
@flo076

Description

@flo076
Issue body actions

Hello

In 1.17.12 of mockito-scala we have a strange behavior.
The method "simpleMethod" is really call.
If we launch the tests "with Spied", the temporary file is created and the method throw "java.lang.ArithmeticException: / by zero". On the contrary the test "with Mock" doesn't have problem.
I don't understand why ? It looks as a bug.

object FooObject {

  def simpleMethod: Int = {
    println("simple method")
    val tmp = Files.createTempFile("simpleMethod", "txt")
    println(s"tmp file path : ${tmp.toFile.getPath}")
    100 / 0
  }

}

class Test extends AnyWordSpec with Matchers with ArgumentMatchersSugar with IdiomaticStubbing {
  "mock" should {
    "with Mock" in {
      withObjectMocked[FooObject.type] {
        FooObject.simpleMethod returns 42
        FooObject.simpleMethod shouldBe 42
      }
    }
    "with Spied" in {
      withObjectSpied[FooObject.type] {
        FooObject.simpleMethod returns 52
        FooObject.simpleMethod shouldBe 52
      }
    }
  }
}
sushi30

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.