mardi 26 janvier 2016

Scala Mock partial stubbing

I'd like to stub one of the methods of a scala class with dependencies. Is there a way to achieve this using ScalaMock?

Here is a simplified example of what I have:

class TeamService(val dep1: D1, val dep2: D2) {

  def method1(param: Int) = param * dep1.magicNumber()

  def method2(param: Int) = {
    method1(param) * 2
  }
}

In this example I'd like to mock method1(). My test would look like:

val teamService = ??? // creates a stub
(teamService.method1 _).when(33, "token").returns(22)
teamService.method2(33).should be(44)

Is there a way to achieve this?

Aucun commentaire:

Enregistrer un commentaire