scala - How can I use MockitoSugar to mock an object (singleton) method? -


is there way in scala use mockitosugar in order mock method of object scala singleton?

your best bet deal singletons mocking first little rework on structure of singleton itself. use trait define operations , have object extend trait so:

trait fooable{   def dofoo:string = "foo" }  object foo extends fooable 

then, in class needs foo object, declare input or can set (di), decalare trait instead this:

class myfoouser(foo:fooable = foo){  } 

that way default uses object, when constructing tests, can give mocked fooable instead. there bunch of ways handle getting fooable classes (this one) , that's not in scope answer. answer using trait first define methods , having object extend trait , referring trait in class needs it. allow mock effectively.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -