Support useConstructor with mockConstruction
Author: Dzeri96Created Apr 14, 2026Updated Apr 14, 2026
This question was sort-of asked in #2769 already, but it got closed without much consideration. I wonder if, a few years after, it's time to reconsider making useConstructor work with mockConstruction.
Take an example like this one:
val mockSettingsFactory: Function[MockedConstruction.Context, MockSettings] = (ctx: MockedConstruction.Context) => {
withSettings
.useConstructor(
ctx.arguments().get(0),
ctx.arguments().get(1),
true
)
}
val mockedMasterClient = mockConstruction(classOf[MasterClient], mockSettingsFactory)MasterClient should have its selected constructor called but the call is simply captured. This leaves us with an uninitialized instance with final fields that can't be changed.
I understand that this uncovers code smells and whatnot, but I'm working on an already-large PR for an open-source project, and I simply have to draw a line as to what I can refactor. I think that this feature would be useful for many working with legacy code.
Source: mockito/mockito