@Test public void testWaitForIncomingEmailWithTimeout() { long start = System.currentTimeMillis(); final long timeout = 2000L; boolean mailReceived = greenMail.waitForIncomingEmail(timeout, 1); long finish = System.currentTimeMillis(); assertThat(mailReceived).isFalse(); final long timePasswdMax = (long) (timeout * 1.1f); assertThat(finish - start).isLessThan(timePasswdMax); final long timePassedMin = (long) (timeout * 0.9f); assertThat(finish - start).isGreaterThan(timePassedMin); }
@Override public boolean waitForIncomingEmail(long timeout, int emailCount) { final CountDownLatch waitObject = managers.getSmtpManager().createAndAddNewWaitObject(emailCount); final long endTime = System.currentTimeMillis() + timeout; while (waitObject.getCount() > 0) { final long waitTime = endTime - System.currentTimeMillis(); if (waitTime < 0L) { return waitObject.getCount() == 0; } try { waitObject.await(waitTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } } return waitObject.getCount() == 0; }
GreenMail extends ConfiguredGreenMail { @Override public boolean waitForIncomingEmail(long timeout, int emailCount) { final CountDownLatch waitObject = managers.getSmtpManager().createAndAddNewWaitObject(emailCount); final long endTime = System.currentTimeMillis() + timeout; while (waitObject.getCount() > 0) { final long waitTime = endTime - System.currentTimeMillis(); if (waitTime < 0L) { return waitObject.getCount() == 0; } try { waitObject.await(waitTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } } return waitObject.getCount() == 0; } }
GreenMail extends ConfiguredGreenMail { @Override public boolean waitForIncomingEmail(long timeout, int emailCount) { final CountDownLatch waitObject = managers.getSmtpManager().createAndAddNewWaitObject(emailCount); final long endTime = System.currentTimeMillis() + timeout; while (waitObject.getCount() > 0) { final long waitTime = endTime - System.currentTimeMillis(); if (waitTime < 0L) { return waitObject.getCount() == 0; } try { waitObject.await(waitTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } } return waitObject.getCount() == 0; } GreenMail();  GreenMail(ServerSetup config);  GreenMail(ServerSetup[] config); }
GreenMail extends ConfiguredGreenMail { @Override public boolean waitForIncomingEmail(long timeout, int emailCount) { final CountDownLatch waitObject = managers.getSmtpManager().createAndAddNewWaitObject(emailCount); final long endTime = System.currentTimeMillis() + timeout; while (waitObject.getCount() > 0) { final long waitTime = endTime - System.currentTimeMillis(); if (waitTime < 0L) { return waitObject.getCount() == 0; } try { waitObject.await(waitTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } } return waitObject.getCount() == 0; } GreenMail();  GreenMail(ServerSetup config);  GreenMail(ServerSetup[] config); @Override synchronized void start(); @Override synchronized void stop(); @Override void reset(); @Override SmtpServer getSmtp(); @Override ImapServer getImap(); @Override Pop3Server getPop3(); @Override SmtpServer getSmtps(); @Override ImapServer getImaps(); @Override Pop3Server getPop3s(); @Override Managers getManagers(); @Override boolean waitForIncomingEmail(long timeout, int emailCount); @Override boolean waitForIncomingEmail(int emailCount); @Override MimeMessage[] getReceivedMessages(); @Override MimeMessage[] getReceivedMessagesForDomain(String domain); @Override GreenMailUser setUser(String login, String password); @Override GreenMailUser setUser(String email, String login, String password); @Override void setQuotaSupported(boolean isEnabled); @Override void setUsers(Properties users); @Override GreenMail withConfiguration(GreenMailConfiguration config); @Override void purgeEmailFromAllMailboxes(); }
GreenMail extends ConfiguredGreenMail { @Override public boolean waitForIncomingEmail(long timeout, int emailCount) { final CountDownLatch waitObject = managers.getSmtpManager().createAndAddNewWaitObject(emailCount); final long endTime = System.currentTimeMillis() + timeout; while (waitObject.getCount() > 0) { final long waitTime = endTime - System.currentTimeMillis(); if (waitTime < 0L) { return waitObject.getCount() == 0; } try { waitObject.await(waitTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } } return waitObject.getCount() == 0; } GreenMail();  GreenMail(ServerSetup config);  GreenMail(ServerSetup[] config); @Override synchronized void start(); @Override synchronized void stop(); @Override void reset(); @Override SmtpServer getSmtp(); @Override ImapServer getImap(); @Override Pop3Server getPop3(); @Override SmtpServer getSmtps(); @Override ImapServer getImaps(); @Override Pop3Server getPop3s(); @Override Managers getManagers(); @Override boolean waitForIncomingEmail(long timeout, int emailCount); @Override boolean waitForIncomingEmail(int emailCount); @Override MimeMessage[] getReceivedMessages(); @Override MimeMessage[] getReceivedMessagesForDomain(String domain); @Override GreenMailUser setUser(String login, String password); @Override GreenMailUser setUser(String email, String login, String password); @Override void setQuotaSupported(boolean isEnabled); @Override void setUsers(Properties users); @Override GreenMail withConfiguration(GreenMailConfiguration config); @Override void purgeEmailFromAllMailboxes();  }