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

How to mock a class which takes a parameter and validates it?

I am trying to mock a org.apache.kafka.clients.producer.KafkaProducer. But the mock fails because of the implementation of the class. The input parameter is validated, if it is null a null pointer exception is thrown. How can I mock it? The reason…
H Sridhar
  • 71
  • 7
0
votes
2 answers

Mocking a case class for testing

I have a case class case class InputCriteria(a: Int) { val b: Int = config.getInt("some path") } How to mock this case class and override the value of b?
0
votes
1 answer

How to mock org.apache.spark.streaming.State with scalamock lib?

I write a unit test for "update function" of Spark.streaming.mapWithState and I need Mock the "org.apache.spark.streaming.State" parameter, but it's a sealed class, compiler complains about an exception: illegal inheritance from sealed class State.…
belle tian
  • 897
  • 8
  • 20
0
votes
1 answer

Mocking elastic4s client getting Type mismatch, How to mock elastic4s client

I'm using elastic4s as my access layer to ElasticSearch, and I'm trying to write some unit tests in my application. I'm using scalaMock as my mocking library. I want to mock the elastic4s client.execute function so I will be able to test my code.…
0
votes
1 answer

Using scalamock to mock an object that does "work" in the constructor

I am trying to mock a class which takes some ctor parameters and does some work in the constructor. Other than wrapping the naughty class I am trying to mock, is there anything in ScalaMock that will actually avoid calling the constructor (as its…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
0
votes
1 answer

ScalaMock - "Unexpected call" error when the call is defined

So I have this test (unfortunately I can't include the full code and failed to reproduce a simplified version): "create method" should { "return OK" in { val offerService: OfferService = mock[OfferService] (offerService.create…
Caballero
  • 11,546
  • 22
  • 103
  • 163
0
votes
1 answer

Scalamock cannot differentiate the Futures

I have a piece of a scala code in class A.scala There is a case class Case1 which contains a field Future of f1 which is of type of another case class Case2. Case2 encloses Seq[String]. I send the case2 object to another class B whose instance is…
user9920500
  • 606
  • 7
  • 21
0
votes
2 answers

ScalaMock mocking generic Java interface overloaded method

I am trying to mock Java generic interface having overloaded method with different number of parameters. Interface code is: import java.util.concurrent.Callable; public interface GOInterface { void send(T record); void send(T record,…
Noam Shaish
  • 1,613
  • 2
  • 16
  • 37
0
votes
1 answer

More descriptive failure message using custom matcher with mockedResource.expects(where(???)) in ScalaMock

I'm working with ScalaMock and ScalaTest to put together some unit tests. I want to use the ScalaMock's expectation syntax to confirm that the service I'm working on passes along acceptable Json to a mocked resource. In this case acceptable means…
0
votes
2 answers

How to avoid duplication of mocked functions signatures in scalamock?

I'm using scalamock to mock this class: class HttpService { def post[In, Out] (url: String, payload: In) (implicit encoder: Encoder[In], decoder: Decoder[Out]) : Future[Out] = ... ... } ...so my test class has a mock used like…
vidi
  • 2,056
  • 16
  • 34
0
votes
1 answer

Using scalamock outside of MockFactory

I want to add integration tests to my project using cucumber feature files. I have got this working using this project as an example: https://github.com/jecklgamis/cucumber-jvm-scala-example The problem I am running into is when I want to mock some…
Richard Deurwaarder
  • 2,023
  • 1
  • 26
  • 40
0
votes
1 answer

How to mock return of None of method which return type is Option[SomeCaseClassDefinedInsideThisClass]

I would expect this test to pass: import org.scalamock.scalatest.MockFactory import org.scalatest.{FlatSpec, Matchers} class FruitImpl { case class FruitName(name: String) def getFruitName: Option[FruitName] = { Some(FruitName("apple")) …
LLCampos
  • 295
  • 4
  • 17
0
votes
1 answer

How can you mock a method call on a trait with ScalaMock?

Before you point to the documentation, please point out what's wrong with this minimal, failing example: import org.scalatest.FlatSpec import org.scalamock.scalatest.proxy.MockFactory class StubbingTest extends FlatSpec with MockFactory { trait…
stewSquared
  • 827
  • 5
  • 24
0
votes
1 answer

How to correct "verify should appear after all code under test has been exercised" when verify is last?

I get the error "verify should appear after all code under test has been exercised" with the following: class CowTest extends MockFactory { Cow.init(testCowProcesses) @Test def noProcessesTest: Unit = { val cow: Cow =…
bbarker
  • 11,636
  • 9
  • 38
  • 62
0
votes
0 answers

ScalaMock test failing for a recursive function

I've created the code to crawl a website. Two questions. The code is supposed to be recursive to get all the links from the same domain, but it stops without retrieving all. I feel there is something wrong in the loop function The test code…
rodbs
  • 185
  • 1
  • 4
  • 12