@Test public void testMailRollsOff() { MailMessage firstMessage = new MailMessageImpl(); firstMessage.appendBody("First Post!"); mailStore.addMessage(firstMessage); assertEquals("First Post!", mailStore.getMessage(0).getBody()); for (int i = 0; i < 100; i++) { addAMessage(); } assertEquals(100, mailStore.getEmailCount()); assertEquals("", mailStore.getMessage(0).getBody()); }
@Test public void testGettingMailFromEmptyMailStoreThrowsIndexOutOfBounds() { try { mailStore.getMessage(0); fail("Should have raised exception."); } catch (IndexOutOfBoundsException ignored) { } }
public void anticipateMessageCountFor(int messageCount, int ticks) { int tickdown = ticks; while (mailStore.getEmailCount() < messageCount && tickdown > 0) { tickdown--; try { Thread.sleep(1); } catch (InterruptedException e) { return; } } }
public int getEmailCount() { return mailStore.getEmailCount(); }
public MailMessage getMessage(int i) { return mailStore.getMessage(i); }
public MailMessage[] getMessagesFor(String recipient) { // TODO Is there a way to implement this without any interface change? return mailStore instanceof RecipientMailStore ? ((RecipientMailStore) mailStore).getMessageFor(recipient) : mailStore.getMessages(); }
public MailMessage[] getMessages() { return mailStore.getMessages(); }
@Test public void testGettingMail0FromMailStoreWithAnItemWorks() { addAMessage(); assertNotNull(mailStore.getMessage(0)); }
@Test public void testAddOneMessageLeavesOneMailInMailMessagesArray() { addAMessage(); assertEquals(1, mailStore.getMessages().length); }
@Test public void testNewMailStoreHasEmptyMailList() { assertEquals(0, mailStore.getMessages().length); }
private void addAMessage() { MailMessage message = new MailMessageImpl(); mailStore.addMessage(message); }
@Test public void testAddOneMessageLeavesOneMail() { addAMessage(); assertEquals(1, mailStore.getEmailCount()); }
@Test public void testNewMailStoreHasNoMail() { assertEquals(0, mailStore.getEmailCount()); }