12
12
import java .io .FileInputStream ;
13
13
import java .io .FileNotFoundException ;
14
14
15
- import com .mashape .unirest .http .exceptions .*;
16
-
17
15
import org .junit .Test ;
18
16
import org .junit .Before ;
19
17
import static org .junit .Assert .*;
@@ -33,10 +31,9 @@ public class SendGridTest {
33
31
email .addTo (address );
34
32
email .addTo (address2 );
35
33
36
- Map correct = new HashMap ();
37
- correct .
put (
"x-smtpapi" ,
"{\" to\" :[\" [email protected] \" ,\" [email protected] \" ]}" );
34
+ String [] correct = {address , address2 };
38
35
39
- assertEquals (correct , email .toWebFormat ());
36
+ assertArrayEquals (correct , email .getTos ());
40
37
}
41
38
42
39
@ Test public void testAddToWithAFrom () {
@@ -47,13 +44,22 @@ public class SendGridTest {
47
44
email .addTo (address );
48
45
email .setFrom (fromaddress );
49
46
50
- Map correct = new HashMap ();
51
- correct .
put (
"x-smtpapi" ,
"{\" to\" :[\" [email protected] \" ]}" );
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 );
54
59
55
- assertEquals ( correct , email . toWebFormat ()) ;
60
+ String [] correct = { name } ;
56
61
62
+ assertArrayEquals (correct , email .getToNames ());
57
63
}
58
64
59
65
@ Test public void testSetFrom () {
@@ -62,11 +68,7 @@ public class SendGridTest {
62
68
String address =
"[email protected] " ;
63
69
email .setFrom (address );
64
70
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 ());
70
72
}
71
73
72
74
@ Test public void testSetFromName () {
@@ -75,10 +77,7 @@ public class SendGridTest {
75
77
String fromname = "Uncle Bob" ;
76
78
email .setFromName (fromname );
77
79
78
- Map correct = new HashMap ();
79
- correct .put ("fromname" , fromname );
80
-
81
- assertEquals (correct , email .toWebFormat ());
80
+ assertEquals (fromname , email .getFromName ());
82
81
}
83
82
84
83
@ Test public void testSetReplyTo () {
@@ -87,10 +86,7 @@ public class SendGridTest {
87
86
String address =
"[email protected] " ;
88
87
email .setReplyTo (address );
89
88
90
- Map correct = new HashMap ();
91
- correct .put ("replyto" , address );
92
-
93
- assertEquals (correct , email .toWebFormat ());
89
+ assertEquals (address , email .getReplyTo ());
94
90
}
95
91
96
92
@ Test public void testAddBcc () {
@@ -99,10 +95,9 @@ public class SendGridTest {
99
95
String address =
"[email protected] " ;
100
96
email .addBcc (address );
101
97
102
- Map correct = new HashMap ();
103
- correct .put ("bcc[0]" , address );
98
+ String [] correct = {address };
104
99
105
- assertEquals (correct , email .toWebFormat ());
100
+ assertArrayEquals (correct , email .getBccs ());
106
101
}
107
102
108
103
@ Test public void testSetSubject () {
@@ -111,10 +106,7 @@ public class SendGridTest {
111
106
String subject = "This is a subject" ;
112
107
email .setSubject (subject );
113
108
114
- Map correct = new HashMap ();
115
- correct .put ("subject" , subject );
116
-
117
- assertEquals (correct , email .toWebFormat ());
109
+ assertEquals (subject , email .getSubject ());
118
110
}
119
111
120
112
@ Test public void testSetText () {
@@ -123,10 +115,7 @@ public class SendGridTest {
123
115
String text = "This is some email text." ;
124
116
email .setText (text );
125
117
126
- Map correct = new HashMap ();
127
- correct .put ("text" , text );
128
-
129
- assertEquals (correct , email .toWebFormat ());
118
+ assertEquals (text , email .getText ());
130
119
}
131
120
132
121
@ Test public void testSetHtml () {
@@ -135,10 +124,7 @@ public class SendGridTest {
135
124
String html = "This is some email text." ;
136
125
email .setHtml (html );
137
126
138
- Map correct = new HashMap ();
139
- correct .put ("html" , html );
140
-
141
- assertEquals (correct , email .toWebFormat ());
127
+ assertEquals (html , email .getHtml ());
142
128
}
143
129
144
130
@ Test public void testAddHeader () {
@@ -147,41 +133,10 @@ public class SendGridTest {
147
133
email .addHeader ("key" , "value" );
148
134
email .addHeader ("other" , "other-value" );
149
135
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" );
168
139
169
- @ Test public void testSend () throws FileNotFoundException , SendGridException {
170
- email = new SendGrid .Email ();
171
-
172
- email .
setFrom (
"[email protected] " );
173
- email .setFromName ("Mailinator" );
174
- email .
setReplyTo (
"[email protected] " );
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 ());
185
141
}
186
-
187
142
}
0 commit comments