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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/***************************************************************************************************
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
**************************************************************************************************/
package at.bitfire.vcard4android.contactrow
import android.net.Uri
import android.provider.ContactsContract.CommonDataKinds
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.LabeledProperty
import at.bitfire.vcard4android.property.CustomType
import ezvcard.parameter.EmailType
import ezvcard.property.Email
import org.junit.Assert.assertEquals
import org.junit.Test
class EmailBuilderTest {
@Test
fun testEmpty() {
EmailBuilder(Uri.EMPTY, null, Contact()).build().also { result ->
assertEquals(0, result.size)
}
}
@Test
fun testAddress_Address() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email("test@example.com"))
}).build().also { result ->
assertEquals(1, result.size)
assertEquals("test@example.com", result[0].values[CommonDataKinds.Email.ADDRESS])
}
}
@Test
fun testAddress_Blank() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email(""))
}).build().also { result ->
assertEquals(0, result.size)
}
}
@Test
fun testLabel() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email("test@example.com"), "Label")
}).build().also { result ->
assertEquals("Label", result[0].values[CommonDataKinds.Email.LABEL])
}
}
@Test
fun testMimeType() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email("test@example.com"))
}).build().also { result ->
assertEquals(CommonDataKinds.Email.CONTENT_ITEM_TYPE, result[0].values[CommonDataKinds.Email.MIMETYPE])
}
}
@Test
fun testPref_None() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email("test@example.com"))
}).build().also { result ->
assertEquals(0, result[0].values[CommonDataKinds.Email.IS_PRIMARY])
}
}
@Test
fun testPref_1() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email("test@example.com").apply {
pref = 1
})
}).build().also { result ->
assertEquals(1, result[0].values[CommonDataKinds.Email.IS_PRIMARY])
}
}
@Test
fun testTypeHome() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email("test@example.com").apply {
types.add(EmailType.HOME)
})
}).build().also { result ->
assertEquals(CommonDataKinds.Email.TYPE_HOME, result[0].values[CommonDataKinds.Email.TYPE])
}
}
@Test
fun testTypeMobile() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email("test@example.com").apply {
types.add(CustomType.Email.MOBILE)
})
}).build().also { result ->
assertEquals(CommonDataKinds.Email.TYPE_MOBILE, result[0].values[CommonDataKinds.Email.TYPE])
}
}
@Test
fun testTypeWork() {
EmailBuilder(Uri.EMPTY, null, Contact().apply {
emails += LabeledProperty(Email("test@example.com").apply {
types.add(EmailType.WORK)
})
}).build().also { result ->
assertEquals(CommonDataKinds.Email.TYPE_WORK, result[0].values[CommonDataKinds.Email.TYPE])
}
}
}
|