@@ -187,36 +187,65 @@ void attachmentException() throws IOException {
187187 }
188188
189189 @ Test
190- void addAttachment () throws IOException {
190+ void addPdfAttachment () throws IOException {
191191 Message message = new Message ("from@example.com" ,"to@example.com" ,"Hello world" , "Hello world" );
192- message .addAttachment (getDefaultFilePath ());
192+ message .addAttachment (getDefaultFilePath () + "/test.pdf" );
193193
194194 HashMap <String ,String > attachment = (HashMap <String , String >) message .getAttachments ().get (0 );
195195 assertEquals (attachment .get ("ContentType" ), "application/pdf" );
196- assertEquals (attachment .get ("Name" ), new File (getDefaultFilePath ()).getName ());
196+ assertEquals (attachment .get ("Name" ), new File (getDefaultFilePath () + "/test.pdf" ).getName ());
197+ assertNotNull (attachment .get ("Content" ));
198+ assertEquals (attachment .get ("ContentId" ), null );
199+ }
200+
201+ @ Test
202+ void addImageAttachment () throws IOException {
203+ String file = getDefaultFilePath () + "/test.jpg" ;
204+ Message message = new Message ("from@example.com" ,"to@example.com" ,"Hello world" , "Hello world" );
205+ message .addAttachment (file );
206+
207+ HashMap <String ,String > attachment = (HashMap <String , String >) message .getAttachments ().get (0 );
208+ assertEquals (attachment .get ("ContentType" ), "image/jpeg" );
209+ assertEquals (attachment .get ("Name" ), new File (file ).getName ());
210+ assertNotNull (attachment .get ("Content" ));
211+ assertEquals (attachment .get ("ContentId" ), null );
212+ }
213+
214+ @ Test
215+ void addTextAttachment () throws IOException {
216+ String file = getDefaultFilePath () + "/test.txt" ;
217+ Message message = new Message ("from@example.com" ,"to@example.com" ,"Hello world" , "Hello world" );
218+ message .addAttachment (file );
219+
220+ HashMap <String ,String > attachment = (HashMap <String , String >) message .getAttachments ().get (0 );
221+ assertEquals (attachment .get ("ContentType" ), "text/plain" );
222+ assertEquals (attachment .get ("Name" ), new File (file ).getName ());
197223 assertNotNull (attachment .get ("Content" ));
198224 assertEquals (attachment .get ("ContentId" ), null );
199225 }
200226
201227 @ Test
202228 void addAttachmentWithContentId () throws IOException {
203229 String contentId = "test-id" ;
230+ String file = getDefaultFilePath () + "/test.pdf" ;
204231 Message message = new Message ("from@example.com" ,"to@example.com" ,"Hello world" , "Hello world" );
205- message .addAttachment (getDefaultFilePath () , contentId );
232+ message .addAttachment (file , contentId );
206233
207234 HashMap <String ,String > attachment = (HashMap <String , String >) message .getAttachments ().get (0 );
208235 assertEquals (attachment .get ("ContentType" ), "application/pdf" );
209- assertEquals (attachment .get ("Name" ), new File (getDefaultFilePath () ).getName ());
236+ assertEquals (attachment .get ("Name" ), new File (file ).getName ());
210237 assertNotNull (attachment .get ("Content" ));
211238 assertEquals (attachment .get ("ContentId" ), contentId );
212239 }
213240
214241 @ Test
215242 void addMultipleAttachments () throws IOException {
216243 String contentId = "test-id" ;
244+ String file1 = getDefaultFilePath () + "/test.pdf" ;
245+ String file2 = getDefaultFilePath () + "/test.jpg" ;
217246 Message message = new Message ("from@example.com" ,"to@example.com" ,"Hello world" , "Hello world" );
218- message .addAttachment (getDefaultFilePath () , contentId );
219- message .addAttachment (getDefaultFilePath () );
247+ message .addAttachment (file1 , contentId );
248+ message .addAttachment (file2 );
220249 assertEquals (message .getAttachments ().size (), 2 );
221250 assertEquals (message .getAttachments ().get (0 ).get ("ContentId" ), contentId );
222251 assertEquals (message .getAttachments ().get (1 ).get ("ContentId" ), null );
0 commit comments