title: Needs to mock beans in integration test case
body: <p>I am writing an integration test case by using testng for spring batch job. In my application, I am using Google API for address and Mail Sender to send the email. In my integration test case, it takes time during a test run for connection and at the end send exception which looks ugly and time-consuming. </p>
  
  <p>I tried to mock the beans but I don't know how to do exactly in an integration test case.</p>
  
  <pre><code>Google Api Code:
  
  @Slf4j
  public final class GoogleApiContext {
  
      private static GeoApiContext context;
  
      private GoogleApiContext() {
      }
  
      public static GeoApiContext getGeoApiContext(String apiKey, int maxQps) {
  
          if (context == null) {
              log.info("Creating google api context having key - {} and maxQps - {}", apiKey, maxQps);
              context = new GeoApiContext.Builder().apiKey(apiKey).queryRateLimit(maxQps).build();
          }
  
          return context;
      }
  
  }
  
  Mail Sender Code:
  
  @Override
      public Boolean sendMailWithAttachment(final MailBo mailBo, final String pathToAttachment, final String fileName) {
          try {
              log.info("Sending Email {}", mailBo);
              MimeMessage message = mailSender.createMimeMessage();
              MimeMessageHelper helper = new MimeMessageHelper(message, true);
              helper.setTo(mailBo.getTo());
              helper.setSubject(mailBo.getSubject());
              helper.setText(mailBo.getText());
              File file = new File(pathToAttachment);
              helper.addAttachment(fileName, file);
              mailSender.send(message);
              log.info("Mail sent successfully");
              return true;
  
          } catch (MessagingException e) {
              log.info("Mail Exception {}", e);
              return false;
          }
      }
  
  Integration Test Case:
  
  @SpringBootTest(
      classes = {ApplicationLauncher.class, BatchConfiguration.class, BatchTestConfig.class})
  public class PostalJobTest extends AbstractTestNGSpringContextTests {
  
    @Autowired
    private JobLauncherTestUtils jobLauncherTestUtils;
  
    @Autowired
    JobLauncher dataloadJobLauncher;
  
    @Autowired
    private Job postalJob;
  
    @Test
    public void testPostalJob_valid_response() throws Exception {
      String fileName = getFileName(FileLocation.POSTAL_VALID, FileLocation.TEMP_POSTAL_VALID);
      JobParametersBuilder jobParametersBuilder = getJobParametersBuilder(fileName);
      jobLauncherTestUtils.setJob(postalJob);
      jobLauncherTestUtils.setJobLauncher(dataloadJobLauncher);
      JobExecution jobExecution =
          jobLauncherTestUtils.launchJob(jobParametersBuilder.toJobParameters());
      Assert.assertEquals(jobExecution.getStatus(), BatchStatus.STARTING);
      Thread.sleep(2000);
      while (jobExecution.isRunning()) {
      }
      Assert.assertEquals(jobExecution.getStatus(), BatchStatus.COMPLETED);
  
  
    }
  </code></pre>
  
  <p>I want to mock GeoApiContext and MailSender for integration test case and if I can create a dummy server to achieve the response so that test runs faster without any exception. Please help me out.</p>