1   /*
2    * Created by IntelliJ IDEA.
3    * User: owen
4    * Date: Nov 25, 2002
5    * Time: 10:45:16 AM
6    * CVS Revision: $Revision: 1.11 $
7    * Last CVS Commit: $Date: 2004/01/06 05:43:19 $
8    * Author of last CVS Commit: $Author: dloeng $
9    * To change this template use Options | File Templates.
10   */
11  package test.mock.mail.server;
12  
13  import com.atlassian.mail.MailException;
14  import com.atlassian.mail.server.MailServer;
15  import com.atlassian.mail.server.PopMailServer;
16  import com.atlassian.mail.server.SMTPMailServer;
17  import com.atlassian.mail.server.managers.AbstractMailServerManager;
18  import com.sun.mail.util.PropUtil;
19  import org.powermock.api.mockito.PowerMockito;
20  import org.powermock.core.classloader.annotations.PrepareForTest;
21  
22  import javax.mail.Authenticator;
23  import javax.mail.NoSuchProviderException;
24  import javax.mail.Session;
25  import javax.mail.Transport;
26  import java.util.List;
27  import java.util.Properties;
28  
29  import static org.mockito.Mockito.mock;
30  import static org.mockito.Mockito.when;
31  
32  @PrepareForTest(Session.class)
33  public class MockMailServerManager extends AbstractMailServerManager
34  {
35      private final Session mockSession;
36      private MailServer server;
37  
38      public MockMailServerManager() throws NoSuchProviderException {
39          mockSession = PowerMockito.mock(Session.class);
40          PowerMockito.mockStatic(PropUtil.class);
41          when(PropUtil.getBooleanSessionProperty(mockSession, "mail.mime.address.strict", true)).thenReturn(false);
42          final Transport mockTransport = mock(Transport.class);
43          when(mockSession.getTransport("smtp")).thenReturn(mockTransport);
44      }
45  
46      public MailServer getMailServer(final Long id) throws MailException
47      {
48          return server;
49      }
50  
51      public MailServer getMailServer(final String name) throws MailException
52      {
53          return null;
54      }
55  
56      public List<String> getServerNames() throws MailException
57      {
58          return null;
59      }
60  
61      public List<SMTPMailServer> getSmtpMailServers()
62      {
63          return null;
64      }
65  
66      public List<PopMailServer> getPopMailServers()
67      {
68          return null;
69      }
70  
71      public Long create(final MailServer mailServer) throws MailException
72      {
73          return null;
74      }
75  
76      public void update(final MailServer mailServer) throws MailException
77      {
78      }
79  
80      public void delete(final Long mailServerId) throws MailException
81      {
82      }
83  
84      public SMTPMailServer getDefaultSMTPMailServer()
85      {
86          return new MockSMTPMailServer(null, "default", "", "", "", false, "mail.atlassian.com", "", "", mockSession);
87      }
88  
89      public PopMailServer getDefaultPopMailServer()
90      {
91          return null;
92      }
93  
94  
95      public Session getSession(Properties props, Authenticator auth)
96      {
97          return mockSession;
98      }
99  }