title: Mock multiple beans in SpringBoot
body: <p>I have a test in SpringBoot that should check multiple beans in very same way:</p>
  
  <pre class="lang-java prettyprint-override"><code>@ExtendWith(SpringExtension.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  public class EndpointsTest implements ApplicationContextAware {
  
      @MockBean
      ComponentA componentA;
      @MockBean
      ComponentB componentB;
  
  ...
  </code></pre>
  
  <p>Since I don't want to write a new dummy test for each component, I though to fetch all beans (hence the usage of <code>ApplicationContextAware</code>) and then to run test on each such bean.</p>
  
  <p>Of course, these beans have to be mocked.</p>
  
  <p>Is there a way to manually mock a bean like the <code>MockBean</code> annotation does and replace it the Spring context? I want also to remove explicit declaration of all components (the number is not small), just for the purpose of mocking.</p>
  
  <p>EDIT: I want to avoid writing manually all the components in the test class. The component beans are named following a convention, so I want to fetch them all, apply the mock and run the test. We have 100+ components.</p>