1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal.factory.users

File UsersMimeMessageIteratorTest.java

 

Code metrics

0
27
2
1
111
70
2
0.07
13.5
2
1

Classes

Class Line # Actions
UsersMimeMessageIteratorTest 57 27 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.mail.internal.factory.users;
21   
22    import java.util.Arrays;
23    import java.util.Collections;
24    import java.util.HashMap;
25    import java.util.List;
26    import java.util.Map;
27    import java.util.Properties;
28   
29    import javax.mail.Message;
30    import javax.mail.MessagingException;
31    import javax.mail.Session;
32    import javax.mail.internet.InternetAddress;
33    import javax.mail.internet.MimeMessage;
34   
35    import org.junit.Test;
36    import org.xwiki.bridge.DocumentAccessBridge;
37    import org.xwiki.component.manager.ComponentManager;
38    import org.xwiki.mail.ExtendedMimeMessage;
39    import org.xwiki.mail.MimeMessageFactory;
40    import org.xwiki.model.reference.DocumentReference;
41   
42    import static org.junit.Assert.assertArrayEquals;
43    import static org.junit.Assert.assertFalse;
44    import static org.junit.Assert.assertTrue;
45    import static org.mockito.ArgumentMatchers.any;
46    import static org.mockito.ArgumentMatchers.eq;
47    import static org.mockito.Mockito.mock;
48    import static org.mockito.Mockito.when;
49   
50    /**
51    * Unit tests for {@link org.xwiki.mail.internal.factory.users.UsersMimeMessageIterator}.
52    *
53    * @version $Id: 15569a5916a25e9f2354389ce4e30b6064735dd6 $
54    * @since 6.4M3
55    */
56    @Deprecated
 
57    public class UsersMimeMessageIteratorTest
58    {
 
59  1 toggle @Test
60    public void createMessage() throws Exception
61    {
62  1 DocumentReference userReference1 = new DocumentReference("xwiki", "XWiki", "JohnDoe");
63  1 DocumentReference userReference2 = new DocumentReference("xwiki", "XWiki", "JaneDoe");
64  1 DocumentReference userReference3 = new DocumentReference("xwiki", "XWiki", "JonnieDoe");
65  1 List<DocumentReference> userReferences = Arrays.asList(userReference1, userReference2, userReference3);
66   
67  1 Session session = Session.getInstance(new Properties());
68   
69  1 MimeMessageFactory factory = new MimeMessageFactory()
70    {
 
71  3 toggle @Override public MimeMessage createMessage(Object source, Map parameters)
72    throws MessagingException
73    {
74  3 return new ExtendedMimeMessage();
75    }
76    };
77   
78  1 Map<String, Object> parameters = new HashMap<>();
79  1 parameters.put("parameters", Collections.EMPTY_MAP);
80  1 parameters.put("session", session);
81   
82  1 DocumentAccessBridge accessBridge = mock(DocumentAccessBridge.class);
83   
84  1 when(accessBridge.getProperty(eq(userReference1), any(DocumentReference.class), eq("email"))).thenReturn(
85    "john@doe.com");
86  1 when(accessBridge.getProperty(eq(userReference2), any(DocumentReference.class), eq("email"))).thenReturn(
87    "jane@doe.com");
88  1 when(accessBridge.getProperty(eq(userReference3), any(DocumentReference.class), eq("email"))).thenReturn(
89    "jannie@doe.com");
90   
91  1 ComponentManager componentManager = mock(ComponentManager.class);
92  1 when(componentManager.getInstance(eq(DocumentAccessBridge.class))).thenReturn(accessBridge);
93   
94  1 UsersMimeMessageIterator iterator =
95    new UsersMimeMessageIterator(userReferences, factory, parameters, componentManager);
96   
97  1 assertTrue(iterator.hasNext());
98  1 MimeMessage message1 = iterator.next();
99  1 assertArrayEquals(message1.getRecipients(Message.RecipientType.TO), InternetAddress.parse("john@doe.com"));
100   
101  1 assertTrue(iterator.hasNext());
102  1 MimeMessage message2 = iterator.next();
103  1 assertArrayEquals(message2.getRecipients(Message.RecipientType.TO), InternetAddress.parse("jane@doe.com"));
104   
105  1 assertTrue(iterator.hasNext());
106  1 MimeMessage message3 = iterator.next();
107  1 assertArrayEquals(message3.getRecipients(Message.RecipientType.TO), InternetAddress.parse("jannie@doe.com"));
108   
109  1 assertFalse(iterator.hasNext());
110    }
111    }