1212import java .io .FileInputStream ;
1313import java .io .FileNotFoundException ;
1414
15- import com .mashape .unirest .http .exceptions .*;
16-
1715import org .junit .Test ;
1816import org .junit .Before ;
1917import static org .junit .Assert .*;
@@ -33,10 +31,9 @@ public class SendGridTest {
3331 email .addTo (address );
3432 email .addTo (address2 );
3533
36- Map correct = new HashMap ();
37- correct .put ("x-smtpapi" , "{\" to\" :[\" email@example.com\" ,\" email2@example.com\" ]}" );
34+ String [] correct = {address , address2 };
3835
39- assertEquals (correct , email .toWebFormat ());
36+ assertArrayEquals (correct , email .getTos ());
4037 }
4138
4239 @ Test public void testAddToWithAFrom () {
@@ -47,13 +44,22 @@ public class SendGridTest {
4744 email .addTo (address );
4845 email .setFrom (fromaddress );
4946
50- Map correct = new HashMap ();
51- correct .put ("x-smtpapi" , "{\" to\" :[\" email@example.com\" ]}" );
52- correct .put ("from" , fromaddress );
53- correct .put ("to" , fromaddress );
47+ String [] correct = {address };
48+
49+ assertArrayEquals (correct , email .getTos ());
50+ assertEquals (fromaddress , email .getFrom ());
51+
52+ }
53+
54+ @ Test public void testAddToName () {
55+ email = new SendGrid .Email ();
56+
57+ String name = "John" ;
58+ email .addToName (name );
5459
55- assertEquals ( correct , email . toWebFormat ()) ;
60+ String [] correct = { name } ;
5661
62+ assertArrayEquals (correct , email .getToNames ());
5763 }
5864
5965 @ Test public void testSetFrom () {
@@ -62,11 +68,7 @@ public class SendGridTest {
6268 String address = "email@example.com" ;
6369 email .setFrom (address );
6470
65- Map correct = new HashMap ();
66- correct .put ("from" , address );
67- correct .put ("to" , address );
68-
69- assertEquals (correct , email .toWebFormat ());
71+ assertEquals (address , email .getFrom ());
7072 }
7173
7274 @ Test public void testSetFromName () {
@@ -75,10 +77,7 @@ public class SendGridTest {
7577 String fromname = "Uncle Bob" ;
7678 email .setFromName (fromname );
7779
78- Map correct = new HashMap ();
79- correct .put ("fromname" , fromname );
80-
81- assertEquals (correct , email .toWebFormat ());
80+ assertEquals (fromname , email .getFromName ());
8281 }
8382
8483 @ Test public void testSetReplyTo () {
@@ -87,10 +86,7 @@ public class SendGridTest {
8786 String address = "email@example.com" ;
8887 email .setReplyTo (address );
8988
90- Map correct = new HashMap ();
91- correct .put ("replyto" , address );
92-
93- assertEquals (correct , email .toWebFormat ());
89+ assertEquals (address , email .getReplyTo ());
9490 }
9591
9692 @ Test public void testAddBcc () {
@@ -99,10 +95,9 @@ public class SendGridTest {
9995 String address = "email@example.com" ;
10096 email .addBcc (address );
10197
102- Map correct = new HashMap ();
103- correct .put ("bcc[0]" , address );
98+ String [] correct = {address };
10499
105- assertEquals (correct , email .toWebFormat ());
100+ assertArrayEquals (correct , email .getBccs ());
106101 }
107102
108103 @ Test public void testSetSubject () {
@@ -111,10 +106,7 @@ public class SendGridTest {
111106 String subject = "This is a subject" ;
112107 email .setSubject (subject );
113108
114- Map correct = new HashMap ();
115- correct .put ("subject" , subject );
116-
117- assertEquals (correct , email .toWebFormat ());
109+ assertEquals (subject , email .getSubject ());
118110 }
119111
120112 @ Test public void testSetText () {
@@ -123,10 +115,7 @@ public class SendGridTest {
123115 String text = "This is some email text." ;
124116 email .setText (text );
125117
126- Map correct = new HashMap ();
127- correct .put ("text" , text );
128-
129- assertEquals (correct , email .toWebFormat ());
118+ assertEquals (text , email .getText ());
130119 }
131120
132121 @ Test public void testSetHtml () {
@@ -135,10 +124,7 @@ public class SendGridTest {
135124 String html = "This is some email text." ;
136125 email .setHtml (html );
137126
138- Map correct = new HashMap ();
139- correct .put ("html" , html );
140-
141- assertEquals (correct , email .toWebFormat ());
127+ assertEquals (html , email .getHtml ());
142128 }
143129
144130 @ Test public void testAddHeader () {
@@ -147,41 +133,10 @@ public class SendGridTest {
147133 email .addHeader ("key" , "value" );
148134 email .addHeader ("other" , "other-value" );
149135
150- Map correct = new HashMap ();
151- correct .put ("headers" , "{\" other\" :\" other-value\" ,\" key\" :\" value\" }" );
152-
153- assertEquals (correct , email .toWebFormat ());
154- }
155-
156- @ Test public void testAddAttachment () throws FileNotFoundException {
157-
158- email = new SendGrid .Email ();
159-
160- File file = new File (getClass ().getResource ("/test.txt" ).getFile ());
161- email .addAttachment ("test.txt" , file );
162-
163- Map correct = new HashMap ();
164- correct .put ("files[test.txt]" , file );
165-
166- assertEquals (correct , email .toWebFormat ());
167- }
136+ Map <String , String > correct = new HashMap <String , String >();
137+ correct .put ("key" , "value" );
138+ correct .put ("other" , "other-value" );
168139
169- @ Test public void testSend () throws FileNotFoundException , SendGridException {
170- email = new SendGrid .Email ();
171- email .addTo ("sendgrid@mailinator.com" );
172- email .setFrom ("sendgrid-from@mailinator.com" );
173- email .setFromName ("Mailinator" );
174- email .setReplyTo ("sendgrid-replyto@mailinator.com" );
175- email .setSubject ("Test" );
176- email .setText ("Test body" );
177- email .setHtml ("Test body" );
178- email .addCategory ("-TEST-" );
179- File file = new File (getClass ().getResource ("/image.png" ).getFile ());
180- email .addAttachment ("image.png" , file );
181- SendGrid sendgrid = new SendGrid (USERNAME , PASSWORD );
182- SendGrid .Response resp = sendgrid .send (email );
183-
184- assertEquals ("{\" message\" :\" error\" ,\" errors\" :[\" Bad username / password\" ]}" , resp .getMessage ());
140+ assertEquals (correct , email .getHeaders ());
185141 }
186-
187142}
0 commit comments