1
votes

There are somewhat contradictory statements about the abilities of ScalaMock to mock (companion) objects and constructors. The page ScalaMock step-by-step states

it can also mock:

  • Classes *Singleton and companion objects (static methods)
  • Object creation (constructor invocation)
  • Classes with private constructors
  • Final classes and classes with final methods
  • Operators (methods with symbolic names)
  • Overloaded methods

On the other hand the roadmap tells me:

First Quarter 2016 - ScalaMock 4 As soon as scala.meta is available, we plan to start working on ScalaMock 4. If scala.meta delivers on its promise, ScalaMock 4 should be able to mock any trait, no matter how complex its type.

In addition, we expect that it will also support:

  • improved syntax: mockObject.expects.method(arguments) instead of: (mockObject.method _) expects (arguments)
  • mocking object creation (constructors)
  • mocking singleton and companion objects (static methods)
  • mocking final classes and classes with final methods or private constructors

So, what is correct? Is the current version (ScalaMock 3.2) able to mock objects and constructors, or not?

1

1 Answers

4
votes

After some more research it looks like mocking objects and constructors was once supported, but isn't in the current version. Mocking of objects should be reintroduced with ScalaMock 4.