Unable to pass type MockedStatic object into method/ constructor
I have this legacy code –
class Mom { Mom(Class StaticBaby){ } }
I’ve used Mockito’s mockstatic (v5.12) to mock out StaticBaby
like
MockedStatic<StaticBaby> mockedStaticBaby = Mockito.mockStatic(StaticBaby.class)
However when I pass mockedStaticBaby
to constructor Mom()
I get java.lang.ClassCastException
Is writing a wrapper around dependency StaticBaby
my only option?
Trying to migrate from Powermock (which supported passing around a static mock into a method) to Mockito, hence the gymnastics and cleanup.
user24031969 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.