Questions tagged [scalamock]

ScalaMock is a mocking framework for the Scala programming language.

ScalaMock provides fully type-safe mocking support for almost all Scala language features including:

  • mocking classes, traits and case classes
  • mocking functions and operators
  • mocking type parameterized and overloaded methods
  • support for type constraints
  • support for repeated parameters and named parameters
  • mocking Java classes and interfaces

The official Web site for the ScalaMock project is http://www.scalamock.org.

148 questions
0
votes
1 answer

ScalaMock and the Cake Pattern - Why is my stub not called?

I have a Scala app that is using the Cake pattern: trait RepositoryComponent { def repository: Repository trait Repository { def shouldSave(record: GenericRecord): Boolean def findRecord(keys: Array[String]): Long def…
Stuart
  • 1,572
  • 4
  • 21
  • 39
0
votes
1 answer

Unable to create stub with Array argument in ScalMock

Here is an example of what I try to achieve. Stub always retuns null, but if I change Array(1L) to * it works. It seems there is a problem with array arguments. trait Repo { def getState(IDs: Array[Long]): String } "test" should "pass" in { …
gorros
  • 1,411
  • 1
  • 18
  • 29
0
votes
1 answer

Scalatest Scalamock behaves differently with same function declared two ways

If I have a Scala trait with two functions defined on it, one defined using just the signature def foo : Int => String and the other function declared with a paramter and a return type def bar(myInt : Int): String then I get different behavior for…
Matt Klein
  • 7,856
  • 6
  • 45
  • 46
0
votes
1 answer

scalamock newexpectationexception - [scala,scalamock,akka-http]

I was playing with ScalaMock. I wrote a KISS version of the error of I facing when I am trying to use ScalaMock to mock an object in a test case. import akka.http.scaladsl.server.Route import org.scalamock.scalatest.MockFactory import…
sdinesh94
  • 1,138
  • 15
  • 32
0
votes
1 answer

How to use ScalaMock not in the tests?

Is this possible to use ScalaMock stub not inside the tests but inside actual code? I want to run http service that require other service witch I want to stub for now. Can't find in documentation how this can be achieved.
sergeda
  • 2,061
  • 3
  • 20
  • 43
0
votes
1 answer

Scalamock: Unable to mock function with typed parameter and multiple implicit variables

This question is an extension of the solved issue mentioned at https://github.com/paulbutcher/ScalaMock/issues/79 I have the following trait to mock: trait HttpClient{ def deserialize[T](response: HttpResponse) (implicit um:…
Agraj
  • 466
  • 5
  • 19
0
votes
2 answers

How to mock a function with view bounds as an argument

I have a function in Scala as follows object MyService extends MyTrait { def myMethod[T <% InvokableBuilder[MyClass]](builder: T): MyResponse = { //do something } } I'm trying to mock this function using mockito like the following val…
0
votes
1 answer

How I can stub abstract java class with protected abstract methods via ScalaMock?

I'm trying to stub abstract java.nio.channels.ServerSocketChannel class but got Error:(15, 18) object creation impossible, since: it has 2 unimplemented members. /** As seen from <$anon: java.nio.channels.ServerSocketChannel>, the missing…
Andrei Tanana
  • 7,932
  • 1
  • 27
  • 36
0
votes
2 answers

ScalaMock Stubbing with default parameters

I'm trying to mock a function like def foo(x: A, y: B, z: C = blah) where blah is a java connection object that I don't want to create on the spot However when I try to stub it like (object.foo _) .stubs(a, b) It errors out and says…
fuzzycuffs
  • 139
  • 1
  • 15
0
votes
1 answer

Does scalamock support mocking curried mehtod that has implicit and repeated parameters?

I need to mock following method using scalamock, but I didn't manage to do it. It is curried, has implicit and repeated parameters in the same time. Does scalamock library support mocking such combination? def apply(key: String, args:…
kraken
  • 484
  • 7
  • 18
0
votes
2 answers

Mocking classes in Play for Scala

I'm planning on using ScalaTest to test Play Controllers, but still undecided if I should mock with Mockito or ScalaMock. The Play website mentions Mockito, however it seems to focus on Java. ScalaMock looks more natural when developing applications…
ps0604
  • 1,227
  • 23
  • 133
  • 330
0
votes
1 answer

ScalaMock Inheritied Trait Function of Object ScalaTest

I am attempting to test a function, however the function that I am testing makes a call to the traits function which I would like to stub. I can't seem to stub this function using ScalaMock, as I am unable to mock the object. trait[A<:CommonReturn]…
Adam Pitt
  • 128
  • 10
0
votes
1 answer

Expect a specific instance for mock in Scalamock

Why can I not tell a mock that it should expect an instance of a class without explicitly giving the type? Here is what I mean: val myClass = new MyClass(...) val traitMock = mock[MyTrait] (traitMock.mymethod…
Make42
  • 12,236
  • 24
  • 79
  • 155
0
votes
1 answer

Scala mock polymorphic methods with implicit type tag

How to mock a polymorphic method with an implicit type tag parameter val mockInterface = mock[SampleInterface] trait SampleInterface { def fetchType[M <: Model : TypeTag]: Future[Unit] }
user1187135
0
votes
4 answers

ScalaMock won't mock my TextMessage

I am using ScalaMock3 and I am trying to create a mock of a javax.jms.TextMessage within my ScalaTest spec. import javax.jms.TextMessage import org.scalamock.scalatest.MockFactory import org.scalatest.{Matchers, WordSpecLike} class MySpec extends…
mdm
  • 3,928
  • 3
  • 27
  • 43
1 2 3
9
10