How can I use MockitoSugar to model an object method (singleton)?

Is there a way in scala to use MockitoSugarto mock a method objectthat is scala singleton?

0
source share
2 answers

It is best to deal with mock singles, to work a bit at first on the structure of the singlet itself. Use a property to define operations, and then the object should expand the stroke as follows:

trait Fooable{
  def doFoo:String = "foo"
}

object Foo extends Fooable

Then, in any class that needs an object Foo, declare it as input or something that can be set (DI), but instead separate it as a property as follows:

class MyFooUser(foo:Fooable = Foo){

}

, , Fooable. Fooable ( ), . , , , , , , . .

+7

Mockito object s, ScalaMock.

0

Source: https://habr.com/ru/post/1654730/


All Articles