Questions tagged [mockito-scala]

Mockito Scala is an open source mocking framework for Scala test development. It is a rewrite of the Mockito framework for Java.

Mockito Scala is an open source mocking framework for Scala test development. It is a rewrite of the Mockito framework for Java.

20 questions
2
votes
1 answer

Wrap argThat in a named function

Say I have something like this (VERY OVER-SIMPLIFIED): case class Foo(bar: String) val mockFnThatTakesFoo = mock[Foo => Unit] def fooHasBarSetTo(expectedBar: String, foo: Foo): Boolean = { val actualBar = foo.bar actualBar shouldEqual…
Daniel Gruszczyk
  • 5,379
  • 8
  • 47
  • 86
2
votes
1 answer

Mocking out all overlaoded versions of a method in scala mockito

In Mockito-Scala you can stub out methods like so: myMock.doIt(*) returns 1 myMock.doIt(*,*) returns 1 myMock.doIt(*,*)(*) returns 1 Is there a way to mock all overloaded methods at once?
Jethro
  • 3,029
  • 3
  • 27
  • 56
2
votes
1 answer

Mocked function doesn't return value class correctly in Scala

I need to mock a function from an arbitrary type to another type that is a value-class. For example with the following signature String => ValueClass. This is how my value-class is implemented: final case class ValueClass(value: String) extends…
mkUltra
  • 2,828
  • 1
  • 22
  • 47
2
votes
2 answers

Mocking a Service that returns Cats EitherT with Guice and MockitoSugar

I am trying to write some functional tests, and I want to mock a service that consumes an external provider. But I can not set up the mock for the functions that return EitherT This is the Trait whose implementation call the external…
agusgambina
  • 6,229
  • 14
  • 54
  • 94
1
vote
1 answer

Pattern for async testing with scalatest and mocking objects with mockito

I am writing unit tests for some async sections of my code (returning Futures) that also involves the need to mock a Scala object. Following these docs, I can successfully mock the object's functions. My question stems from the fact that…
anqit
  • 780
  • 3
  • 12
1
vote
0 answers

Argument matchers for type parameters when using Mockito

I was trying to find out if I can use something like the any argument matcher for a method with type parameters: when(store.getItems[Product](any[FilterParams])) .thenReturn(allProducts) When running the code with the above snippet, I get…
1
vote
1 answer

How to use MockitoSugar with AsyncFunSuite in Scalatest?

I'm not able to use MockitoSugar along with AsyncFunSuite. In short: This example works (taken from Scalatest documentation) class AddSuite extends AsyncFunSuite { def addSoon(addends: Int*): Future[Int] = Future { addends.sum } test("addSoon…
krismath
  • 1,879
  • 2
  • 23
  • 41
1
vote
1 answer

Mockito mocking Akka Streams

When unit testing, what is the best approach to mocking out Akka Streams calls involving Sources, Flows and Sinks? For example, the takeWhile function: def takeWhile(p: Out => Boolean): Repr[Out] Where Repr is a trait within a trait: trait…
Jethro
  • 3,029
  • 3
  • 27
  • 56
1
vote
1 answer

How do you check a mock was called with a Seq irrespective of order

I have a method, which has been mocked, and takes a Seq as a parameter. I want to check the method was called with a Seq with the same contents, but irrespective of order. eg something like: myMethod(Seq(0,1)) wasCalled once which passes if we…
Jethro
  • 3,029
  • 3
  • 27
  • 56
1
vote
1 answer

Scala type system, cannot find common ancestor inline

I am on an heavily typed system with some generic methods declared as def execute]C <: A#C](cmd: C):EitherT[Future, Fail, Seq[A#E]] (where A is a generic type on the class. This works well. However in my tests, when I mock those calls, I have to…
gervais.b
  • 2,294
  • 2
  • 22
  • 46
0
votes
0 answers

Whats the simpler way to mock call to classes from the `java.time` classes in Scala?

In javascript for example the jest library has a facility to kind of travel through time to test time dependent code, here, or in ruby on rails you have facilities to mock time like this. I'm looking for something similar in Scala that could allow…
Miguel Salas
  • 692
  • 1
  • 6
  • 21
0
votes
1 answer

Mocked methods created within `withObjectMocked` not invoked when called from an `Actor`

I have published a minimal project showcasing my problem at https://github.com/Zwackelmann/mockito-actor-test In my project I refactored a couple of components from classes to objects in all cases where the class did not really have a meaningful…
Zwackelmann
  • 557
  • 1
  • 5
  • 19
0
votes
1 answer

Is it possible to mock multiple Scala Objects in the same test?

Say I have the following object I want to test object ObjectToTest { def apply() = { val example = List.fill(5)(CaseClassExample("here", "there")) ChildObject(example.tail) + " " + ChildObject2(example.tail) } } where both child…
l33tHax0r
  • 1,384
  • 1
  • 15
  • 31
0
votes
0 answers

How do I specify that a mock has no interactions after a given timeout in mockito-scala?

I can't find a nice Scala DSL way to specify that a mock was not called at all after a specified duration. Something like aMock wasNever calledAgain after 2.seconds The doc also doesn't mention anthing.…
Chris W.
  • 2,266
  • 20
  • 40
0
votes
0 answers

mockito-scala verify method invocation

I raised a fake issue on mockito-scala : https://github.com/mockito/mockito-scala/issues/191 But I am still stuck with my problem. So basically, I have stubbed answers for one method. I am sure that the stubbed method is executed with the correct…
gervais.b
  • 2,294
  • 2
  • 22
  • 46
1
2