// Copyright (c) 2003-present, Jodd Team (http://jodd.org)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

package jodd.mail;

import org.junit.jupiter.api.Test;

import java.util.Properties;

import static jodd.mail.SmtpServer.MAIL_SMTP_FROM;
import static org.junit.jupiter.api.Assertions.assertEquals;

class SmtpServerTest {

    private static final String HOST = "some.host.com";
    private static final int PORT = 587;
    private static final String FROM = "bounce@jodd.org";
    private static final String USERNAME = "test";
    private static final String PASSWORD = "password";

    @Test
    void testAddsPropertyToServerSession() {
        Properties overridenProperties = new Properties();

        overridenProperties.setProperty(MAIL_SMTP_FROM, FROM);

        SmtpServer smtpServer = SmtpServer.create(HOST, PORT)
                .authenticateWith(USERNAME, PASSWORD)
                .timeout(10)
                .properties(overridenProperties);

        assertFrom(smtpServer);
    }

    @Test
    void testAddsPropertyToServerSession2() {
        SmtpSslServer smtpServer = SmtpSslServer.create(HOST, PORT)
                .authenticateWith(USERNAME, PASSWORD)
                .timeout(10)
                .property(MAIL_SMTP_FROM, FROM);
        assertFrom(smtpServer);
    }

    private void assertFrom(MailServer server) {
        Properties sessionProperties = server.createSession().mailSession.getProperties();
        assertEquals(FROM, sessionProperties.getProperty(MAIL_SMTP_FROM));
    }
}

@@ -1599,18 +1599,16 @@
 Test %7B%0A%0A
-  
   privat
@@ -1629,20 +1629,29 @@
  String 
-HOST
+SOME_HOST_COM
  = %22some
@@ -1660,26 +1660,24 @@
 ost.com%22;%0A  
- 
- 
 private stat
@@ -1701,18 +1701,16 @@
  = 587;%0A
-  
   privat
@@ -1757,18 +1757,16 @@
 d.org%22;%0A
-  
   privat
@@ -1808,18 +1808,16 @@
 est%22;%0A  
- 
- 
 private 
@@ -1860,26 +1860,24 @@
 word%22;%0A%0A
-  
   @Test%0A
     void
@@ -1860,34 +1860,32 @@
 word%22;%0A%0A  @Test%0A
-  
   void testAddsP
@@ -1907,35 +1907,37 @@
 Session() %7B%0A    
-   
+final
  Properties over
@@ -1969,28 +1969,24 @@
 perties();%0A%0A
-    
     override
@@ -2033,27 +2033,29 @@
 FROM);%0A%0A    
-   
+final
  SmtpServer 
@@ -2071,69 +2071,89 @@
 r = 
-Smtp
+Mail
 Server.
-create(HOST, PORT)%0A                .authenticateWi
+builder()%0A        .host(SOME_HOST_COM)%0A        .port(PORT)%0A        .au
 th(U
@@ -2171,32 +2171,45 @@
 SSWORD)%0A        
+.buildSmtp()%0A
         .timeout
@@ -2212,35 +2212,45 @@
 eout(10)
+;%0A
 %0A    
-            .p
+smtpServer.getSessionP
 ropertie
@@ -2251,16 +2251,25 @@
 perties(
+).putAll(
 override
@@ -2283,20 +2283,16 @@
 ties);%0A%0A
-    
     asse
@@ -2315,27 +2315,21 @@
 r);%0A
-  
   %7D%0A%0A  
- 
- 
 @Test%0A
-  
   vo
@@ -2372,19 +2372,21 @@
 ) %7B%0A    
-   
+final
  SmtpSsl
@@ -2409,22 +2409,19 @@
 r = 
-SmtpSs
+Mai
 lServer.
 crea
@@ -2420,35 +2420,67 @@
 ver.
-create(HOST, PORT)%0A        
+builder()%0A        .host(SOME_HOST_COM)%0A        .port(PORT)%0A
     
@@ -2492,20 +2492,8 @@
 auth
-enticateWith
 (USE
@@ -2517,24 +2517,31 @@
         
-        
+.buildSmtpSsl()
 .timeout
@@ -2548,27 +2548,53 @@
 (10)
+;%0A
 %0A    
-            .p
+smtpServer.getSessionProperties().setP
 rope
@@ -2620,24 +2620,21 @@
  FROM);%0A
-   
+%0A
     
- 
 assertFr
@@ -2653,17 +2653,13 @@
 r);%0A
-  
   %7D%0A%0A
-  
   pr
@@ -2680,16 +2680,22 @@
 ertFrom(
+final 
 MailServ
@@ -2711,19 +2711,21 @@
 ) %7B%0A    
-   
+final
  Propert
@@ -2775,19 +2775,20 @@
 n().
-mail
+get
 Session
+()
 .get
@@ -2801,20 +2801,16 @@
 ties();%0A
-    
     asse
@@ -2872,16 +2872,14 @@
 FROM));%0A
-  
   %7D%0A%7D%0A

Use final and new method of updating properties.