In my SpringBootApplication, I have a bean which injects another optional bean (like shown below)
@Service
public class A {
//B is another @Component from one of the dependencies
private Optional<B> b;
...
...
}
I am writing an integration test for class A where I need to @MockBean Optional<B> b. However since Optional is a final class, spring mockito raises following error
Cannot mock/spy class java.util.Optional - final class
Is there a way around this? Any help is much appreciated.