MailHandler { public void sendMail(String to, String subject, String body, InputStream inputStream, String attachmentFileName) throws MessagingException, IOException { LOGGER.info("Sending email"); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setTo(to); mimeMessageHelper.setText(body); mimeMessageHelper.addAttachment(attachmentFileName, new ByteArrayResource(IOUtils.toByteArray(inputStream))); mailSender.send(mimeMessageHelper.getMimeMessage()); } @Autowired  MailHandler(JavaMailSender mailSender); void sendMail(String to, String subject, String body, InputStream inputStream, String
            attachmentFileName);  }
@Test public void testSendMail() { String to = "x@xxx.com"; String subject = "Test Mail"; String body = "Test Body"; String attachmentFileName = "Test File Name"; InputStream inputStream; try { inputStream = new FileInputStream("/home/deshani/Documents/uploaded"); mailHandler.sendMail(to, subject, body, inputStream, attachmentFileName); } catch (MessagingException | IOException e) { assertTrue(false); } }