In an integration test (@SpringBootTest)
class I declare a spyBean:
@SpyBean
private Environment environment;
In a test I try to mock one method:
doReturn(true).when(environment).acceptsProfiles(Profiles.of("prod"));
However, I get the following error:
org.mockito.exceptions.misusing.NotAMockException:
Argument passed to when() is not a mock!
Example of correct stubbing:
doThrow(new RuntimeException()).when(mock).someMethod();
How can I properly mock the method?