MailReport { public void sendReportMail(Collector collector, boolean collectorServer, List<JavaInformations> javaInformationsList, Period period) throws Exception { final File tmpFile = new File(Parameters.TEMPORARY_DIRECTORY, PdfReport.getFileName(collector.getApplication())); try { final OutputStream output = new BufferedOutputStream(new FileOutputStream(tmpFile)); try { final PdfReport pdfReport = new PdfReport(collector, collectorServer, javaInformationsList, period, output); pdfReport.toPdf(); } finally { output.close(); } final String subject; final String subjectPrefix = Parameter.MAIL_SUBJECT_PREFIX.getValue(); if (subjectPrefix != null) { subject = MessageFormat.format(subjectPrefix.replace("'", "''"), collector.getApplication()) + " - " + period.getLabel(); } else { subject = I18N.getFormattedString("Monitoring_sur", collector.getApplication()) + " - " + period.getLabel(); } final Mailer mailer = new Mailer(Parameter.MAIL_SESSION.getValue()); final String adminEmails = Parameter.ADMIN_EMAILS.getValue(); mailer.send(adminEmails, subject, "", Collections.singletonList(tmpFile), false); } finally { if (!tmpFile.delete()) { tmpFile.deleteOnExit(); } } }  static void scheduleReportMailForLocalServer(Collector collector, Timer timer); static List<Period> getMailPeriods(); static Date getNextExecutionDate(Period period); void sendReportMailForLocalServer(Collector collector, Period period); void sendReportMail(Collector collector, boolean collectorServer,
			List<JavaInformations> javaInformationsList, Period period);  }
@Test public void testSendReportMail() throws Exception { final Counter counter = new Counter("http", null); final Collector collector = new Collector("test", Collections.singletonList(counter)); final List<JavaInformations> javaInformationslist = Collections .singletonList(new JavaInformations(null, true)); setProperty(Parameter.ADMIN_EMAILS, "evernat@free.fr"); setProperty(Parameter.MAIL_SESSION, "mail/Session"); try { new MailReport().sendReportMail(collector, false, javaInformationslist, Period.SEMAINE); } catch (final NoInitialContextException e) { assertNotNull("ok", e); } setProperty(Parameter.MAIL_SUBJECT_PREFIX, "[javamelody] "); try { new MailReport().sendReportMail(collector, false, javaInformationslist, Period.SEMAINE); } catch (final NoInitialContextException e) { assertNotNull("ok", e); } final String path = "path"; final ServletContext context = createNiceMock(ServletContext.class); expect(context.getMajorVersion()).andReturn(3).anyTimes(); expect(context.getMinorVersion()).andReturn(0).anyTimes(); expect(context.getContextPath()).andReturn(path).anyTimes(); replay(context); Parameters.initialize(context); try { new MailReport().sendReportMailForLocalServer(collector, Period.SEMAINE); } catch (final NoInitialContextException e) { assertNotNull("ok", e); } verify(context); }