-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathDistListTest.java
More file actions
63 lines (60 loc) · 2.47 KB
/
DistListTest.java
File metadata and controls
63 lines (60 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.pff;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashSet;
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Tests for {@link PSTDistList}.
*
* @author Richard Johnson
*/
@RunWith(JUnit4.class)
public class DistListTest {
/**
* Test we can retrieve distribution lists from the PST.
*/
@Test
public final void testGetDistList()
throws PSTException, IOException, URISyntaxException {
URL dirUrl = ClassLoader.getSystemResource("dist-list.pst");
PSTFile pstFile = new PSTFile(new File(dirUrl.toURI()));
PSTDistList obj = (PSTDistList)PSTObject.detectAndLoadPSTObject(pstFile, 2097188);
Object[] members = obj.getDistributionListMembers();
Assert.assertEquals("Correct number of members", members.length, 3);
int numberOfContacts = 0;
int numberOfOneOffRecords = 0;
HashSet<String> emailAddresses = new HashSet<String>();
HashSet<String> displayNames = new HashSet<String>();
for (Object member : members) {
if (member instanceof PSTContact) {
PSTContact contact = (PSTContact)member;
Assert.assertEquals("Contact email address",
contact.getEmail1EmailAddress(),
numberOfContacts++;
} else {
PSTDistList.OneOffEntry entry = (PSTDistList.OneOffEntry)member;
emailAddresses.add(entry.getEmailAddress());
displayNames.add(entry.getDisplayName());
numberOfOneOffRecords++;
}
}
Assert.assertEquals("Correct number of members", members.length, 3);
Assert.assertEquals("Contains all display names",
displayNames,
new HashSet<String>(Arrays.asList(
new String[] {"dist name 2",
"dist name 1"})));
Assert.assertEquals("Contains all email addresses",
emailAddresses,
new HashSet<String>(Arrays.asList(
"[email protected]"})));
}
}