SendEmailController { @RequestMapping(value = "/sendEmail", method = RequestMethod.POST) public String register(@Validated(Create.class) @RequestBody Plan plan) throws MessagingException { StringBuffer body = new StringBuffer(); List<Plan> list = new ArrayList<Plan>(); List<Integer> listId = plan.getIdList(); User user = userService.findOne(plan.getUserId()); String email = user.getEmail(); for (Integer planList : listId) { list.add(planService.getPlansByPlaceId(planList)); } body.append("<html>"); body.append("<body><head><style>" + "table, th, td {" + " border: 1px solid black;" + " border-collapse: collapse;" + "}" + "</style></head>"); body.append("Dear <b>" + user.getUserName() + "</b>"); body.append("<table>" + " <tr>" + "<th>Plan</th>" + "<th>Hotel</th>" + "<th>Address</th>" + "<th>Temperature</th>" + "<th>Date Added</th>" + "<th>Date of travel</th>" + "</tr>"); for (Plan planDetails : list) { body.append("<tr>"); body.append("<td>" + planDetails.getPlace() + "</td>" + "<td>" + planDetails.getHotel() + "</td>" + "<td>" + planDetails.getAddress() + "</td>" + "<td>" + planDetails.getClimate() + "</td>" + "<td>" + planDetails.getDateAdded() + "</td>" + "<td>" + planDetails.getDateTravel() + "</td>" + "</tr>"); } body.append("</table>"); body.append("</body></html>"); String subject = "Your Plan Confirmation"; return emailService.sendEmail(email, subject, body.toString()); } @Autowired  SendEmailController(EmailService emailService);  SendEmailController(); @RequestMapping(value = "/sendEmail", method = RequestMethod.POST) String register(@Validated(Create.class) @RequestBody Plan plan); @RequestMapping(value = "/shareEmail", method = RequestMethod.POST) String shareEmail(@Validated(Create.class) @RequestBody Plan plan); void setServices(PlanService planService, UserService userService, EmailService emailService); List<Plan> constructEmail(Plan plan);  }
@Test public void testSendEmail(){ try { assertEquals("Success", controller.register(plan)); } catch (MessagingException e) { e.printStackTrace(); } }