Scalatest and mockito: spy not working as expected

Viewed 58

I am using scalatest+mockito for unit tests. I have set a spy on an object to check if target method is actually invoking another method or not.

"Find all modules" in { f =>
      for {
        _ <- f.moduleService.persist(....)
        _ <- f.moduleService.persist(....)
        _ <- f.moduleService.persist(....)
        serviceSpy = spy(f.moduleService)
        result <- f.moduleService.findModules(
          someArguments,
          None,
          Some(false)
        )
      } yield {
        verify(serviceSpy, times(1)).moduleQueries(None, Some(false))
        result.size shouldBe 3
      }
    }

I expect that moduleQueries is invoked with arguments None, Some(false), and during debugging its actually called.

But its failing with

Caused by: Wanted but not invoked:
moduleService.moduleQueries(
    None,
    Some(false)
);
Actually, there were zero interactions with this mock.
0 Answers
Related