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
1
vote
1 answer

Scalamock expect eventually

I'm using scalamock to write a test. The problem is that action is asynchronous. I have the following pseudo code val resultCollectorMock = mock[ResultCollector] (resultCollectorMock.collectResult _).expect(someResult) val serviceUnderTest = new…
mjjaniec
  • 793
  • 1
  • 8
  • 19
1
vote
0 answers

How to mock a class with type parameters using Scalamock?

I'm trying to mock this Scala class using Scalamock v4.4.0: import com.twitter.util.closable class SimpleKafkaProducer[K, V](val kafkaProducer: KafkaProducer[K, V], val topic: String) extends Closable {...} In my test I have: val…
sentenza
  • 1,608
  • 3
  • 29
  • 51
1
vote
1 answer

Scalamock: Mocking call by-name function with arguments

In following code snippet, I need to ensure that BinaryConverter#intToStr is invoked. import org.scalamock.scalatest.MockFactory import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers class Foo { def foo(x: Int)(b:…
rojanu
  • 1,592
  • 5
  • 20
  • 34
1
vote
1 answer

Scala Mock: MockFunction0-1() once (never called - UNSATISFIED)

I'm working on a scala object in order to perform some testing My start object is as follows object obj1 { def readvalue : IO[Float] = IO{ scala.io.StdIn.readFloat() } } The testing should be 1- value of type FLOAT 2- should be less than 3 As we…
Her sincerly
  • 373
  • 1
  • 13
1
vote
1 answer

Cannot mock the RedisClient class - method pipeline overrides nothing

I have a CacheService class that uses an instance of the scala-redis library class CacheService(redisClient: RedisClient) extend HealthCheck { private val client = redisClient override def health: Future[ServiceHealth] = { client.info …
1
vote
1 answer

Scalamock : How to specify arbitrary sequence of tuples

I am trying to create a mock for Play's WSClient like this: def mockGet[A](url : String, method : String, headers : Seq[(String, String)], timeout : Duration)( response: Future[AhcWSResponse] ) = (mockWsClient .url(_ : String) …
Mojo
  • 1,152
  • 1
  • 8
  • 16
1
vote
1 answer

scalamock create basic setup and easily change it

I started writing my own MockSetter, to make some basic mocks before each tests, on in every of it be able to change of of them or add new one. Trait for Spec looks like: trait MocksSetter extends MockFactory with BeforeAndAfterEach { self: Suite…
FrancMo
  • 2,459
  • 2
  • 19
  • 39
1
vote
1 answer

ScalaMock, returns based on a ClassTag

How can I stub a method that use a ClassTag in the implementation ? class RefsFactory { def get[I <: Item : ClassTag]: RefTo[I] = { val itemType = implicitly[ClassTag[A]].runtimeClass.asInstanceOf[Class[A]] // ... } } This class is used…
gervais.b
  • 2,294
  • 2
  • 22
  • 46
1
vote
2 answers

NoSuchMethodError: java.lang.String.lines()Ljava/util/stream/Stream; when trying to run a test with ScalaMock

I'm using ScalaTest and ScalaMock and I run into an exception preventing my test to even run. An exception or error caused a run to abort: java.lang.String.lines()Ljava/util/stream/Stream; I'm using Scala 2.13, JDK 8 and the latest versions of the…
poffuomo
  • 11
  • 1
  • 5
1
vote
1 answer

How can I mock DynamoDB access via Spark in Scala?

I have a Spark job written in Scala that ultimately writes out to AWS DynamoDB. I want to write some unit tests around it, but the only problem is I don't have a clue how to go about mocking the bit that writes to DynamoDB. I'm making use of their…
soapergem
  • 9,263
  • 18
  • 96
  • 152
1
vote
0 answers

How can I mock the Hadoop FileStatus class using Scalamock?

I am trying to mock the FileStatus class from the Hadoop common API Java library. The following compiler errors result: Error:(34, 24) double definition: override def compareTo(o: Any): Int at line 34 and override def compareTo(x$1: T): Int at line…
Jeff Evans
  • 1,257
  • 1
  • 15
  • 31
1
vote
1 answer

How to fix scala mock error where the implicit arg is not specified?

I have a class I am trying to mock with scala mock but I am getting a compilation error. How can I correct this error or specify the implicit correctly? It says the implicit arg is unspecified. I tried following the guide on the scala mock site. I…
SPD
  • 363
  • 1
  • 2
  • 15
1
vote
1 answer

mocking method inside another method scala

I am having a problem while mocking a method that is being called in another method. For example: Below in my main class. class Trial extends TrialTrait { def run(): String ={ val a = createA() val b = a.split(" ") val c = b.size …
1
vote
1 answer

How to return a value of Right value of Either in Scala test

I have a method which returns Either[Exception, String] class A { def validate(a: Any) = { case a: String => Left(...some.. exception) case a: Any => Right(a) } } class B(a: A) { def callValidate(any: Any) = { …
user9920500
  • 606
  • 7
  • 21
1
vote
2 answers

How to create mock object of a class which is package private

I have a class. It has a companion object A with a factory method. class A private[somepackage](x: Int) { } object A { def createA(y: Int): A = { new A(y) } } Now I need to create the mock object of A in a scalatest file which is in a different…
user9920500
  • 606
  • 7
  • 21