package com.dumbster.smtp;

import com.dumbster.smtp.SmtpServer;
import com.dumbster.smtp.MailMessage;

import org.junit.*;
import static org.junit.Assert.*;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class MockitoTestCases {

	private SmtpServer server;

	@Before
	public void setup(){
		server = mock(SmtpServer.class);
	}

	@Test
	public void mockServer() {
		assertEquals(0, server.getEmailCount());
	}

	/* Helpers */

	private void setupMockServerTest() {
		when(server.getEmailCount()).thenReturn(0);
	}

}
@@ -108,89 +108,194 @@
 ort 
-org.junit.*;%0Aimport static org.junit.Asser
+javax.activation.DataHandler;%0Aimport javax.activation.DataSource;%0Aimport javax.mail.*;%0Aimport javax.mail.interne
 t.*;%0A
-%0A
 import 
-static org.mockito.Mock
+java.util.Properties;%0Aimport java.util.Date;%0A%0Aimport org.jun
 it
-o
 .*;%0A
@@ -316,29 +316,24 @@
 org.
-mockito.Mockito.mock;
+junit.Assert.*;%0A
 %0Aimp
@@ -363,20 +363,17 @@
 Mockito.
-when
+*
 ;%0A%0Apubli
@@ -427,16 +427,329 @@
  server;
+%0A%09private MailMessage mm;%0A%0A%09private static final int SMTP_PORT = 1081;%0A%09private final String SUBJECT = %22Message Subject%22;%0A%09private final String SERVER = %22localhost%22;%0A    private final String FROM = %22sender@here.com%22;%0A    private final String TO = %22receiver@there.com%22;%0A    private final String BODY = %22Test Body%22;
 %0A%0A%09@Befo
@@ -808,16 +808,48 @@
 class);%0A
+%09%09mm = mock(MailMessage.class);%0A
 %09%7D%0A%0A%09@Te
@@ -878,51 +878,373 @@
 rver
-() %7B%0A%09%09assertEquals(0, server.getEmailCount
+NoEmails() %7B%0A%09%09setupMockServerNoEmailsTest();%0A%09%09assertEquals(0, server.getEmailCount());%0A%09%7D%0A%0A%09@Test%0A%09public void mockServerWithEmails() %7B%0A%09%09setupMockServerWithEmailsTest();%0A%09%09sendMessage(SMTP_PORT, FROM, SUBJECT, BODY, TO);%0A%09%09assertEquals(1, server.getEmailCount());%0A%09%09assertEquals(SUBJECT, mm.getFirstHeaderValue(%22Subject%22));%0A%09%09assertEquals(%22Test Body%22, mm.getBody
 ());
@@ -1293,16 +1293,24 @@
 ckServer
+NoEmails
 Test() %7B
@@ -1360,9 +1360,668 @@
 0);%0A%09%7D%0A%0A
+%09private void setupMockServerWithEmailsTest() %7B%0A%09%09when(mm.getFirstHeaderValue(%22Subject%22)).thenReturn(SUBJECT);%0A%09%09when(server.getEmailCount()).thenReturn(1);%0A%09%09when(mm.getBody()).thenReturn(%22Test Body%22);%0A%09%7D%0A%0A%09private void sendMessage(int port, String from, String subject, String body, String to) %7B%0A    try %7B%0A        Properties mailProps = getMailProperties(port);%0A        Session session = Session.getInstance(mailProps, null);%0A%0A        MimeMessage msg = createMessage(session, from, to, subject, body);%0A        Transport.send(msg);%0A        %7D %0A    catch (Exception e) %7B%0A        e.printStackTrace();%0A        fail(%22Unexpected exception: %22 + e);%0A        %7D%0A    %7D%0A
 %7D

Test case 2