package io.jstack.sendcloud4j.mail;


import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

import static org.junit.Assert.assertEquals;

public class TemplateEmailTest {
    Logger logger = LoggerFactory.getLogger(TemplateEmailTest.class);

    private static final String NOT_USE_ADD_XSMTPAPI = "{\"to\":[\"denger.it@gmail.com\"],\"sub\":{\"%name%\":[\"Jack\"]}}";

    @Test
    public void testRewriteParametersWhenNotUseAddressList() {
        TemplateEmail templateEmail = new TemplateEmail("test_tmp")
                .to("denger.it@gmail.com")
                .substitutionVars(Substitution.sub().set("name", "Jack"));

        Map<String, String> params = templateEmail.getParameters();
        assertEquals(params.get("to"), null);
        assertEquals(params.get("xsmtpapi"), NOT_USE_ADD_XSMTPAPI);

        logger.info("Not use address list: {}", params);
    }

    @Test
    public void testRewriteParametersWhenUseAddressList() {
        TemplateEmail templateEmail = new TemplateEmail("test_tmp")
                .to("denger.it@gmail.com")
                .useAddressList()
                .substitutionVars(Substitution.sub().set("name", "Jack"));

        Map<String, String> params = templateEmail.getParameters();
        assertEquals(params.get("to"), "denger.it@gmail.com");
        assertEquals(params.get("xsmtpapi"), null);

        logger.info("used address list: {}", params);
    }

}

@@ -179,16 +179,59 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Apublic
@@ -384,17 +384,16 @@
 PAPI = %22
-%7B
 %5C%22to%5C%22:%5B
@@ -420,41 +420,8 @@
 m%5C%22%5D
-,%5C%22sub%5C%22:%7B%5C%22%25name%25%5C%22:%5B%5C%22Jack%5C%22%5D%7D%7D
 %22;%0A%0A
@@ -740,32 +740,90 @@
 etParameters();%0A
+        logger.info(%22Not use address list: %7B%7D%22, params);%0A%0A
         assertEq
@@ -858,38 +858,36 @@
 ;%0A        assert
-Equals
+True
 (params.get(%22xsm
@@ -893,18 +893,26 @@
 mtpapi%22)
-, 
+.contains(
 NOT_USE_
@@ -928,65 +928,8 @@
 API)
-;%0A%0A        logger.info(%22Not use address list: %7B%7D%22, params
 );%0A 
@@ -1285,32 +1285,87 @@
 etParameters();%0A
+        logger.info(%22used address list: %7B%7D%22, params);%0A%0A
         assertEq
@@ -1466,63 +1466,8 @@
 ll);
-%0A%0A        logger.info(%22used address list: %7B%7D%22, params);
 %0A   

fix unittest