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
122
123
124
125
126
127
128
129
130
131
132
|
/***************************************************************************************************
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
**************************************************************************************************/
package at.bitfire.vcard4android.contactrow
import android.content.ContentValues
import android.provider.ContactsContract.CommonDataKinds.Im
import at.bitfire.vcard4android.Contact
import ezvcard.parameter.ImppType
import org.junit.Assert.*
import org.junit.Test
class ImHandlerTest {
@Test
fun testHandle_Empty() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM)
put(Im.CUSTOM_PROTOCOL, "new-messenger")
}, contact)
assertTrue(contact.impps.isEmpty())
}
@Test
fun testHandle_Value() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM)
put(Im.CUSTOM_PROTOCOL, "new-messenger")
put(Im.DATA, "messenger-id")
}, contact)
assertEquals("messenger-id", contact.impps[0].property.handle)
}
@Test
fun testProtocol_Custom() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM)
put(Im.CUSTOM_PROTOCOL, "new-messenger")
put(Im.DATA, "id")
}, contact)
assertEquals("new-messenger", contact.impps[0].property.protocol)
}
@Test
fun testProtocol_Empty() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
putNull(Im.PROTOCOL)
}, contact)
assertTrue(contact.impps.isEmpty())
}
@Test
fun testProtocol_Legacy_Aim() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_AIM)
put(Im.DATA, "aim-id")
}, contact)
assertEquals("aim", contact.impps[0].property.protocol)
}
@Test
fun testTypeCustom_NoLabel() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM)
put(Im.CUSTOM_PROTOCOL, "new-messenger")
put(Im.DATA, "messenger-id")
put(Im.TYPE, Im.TYPE_CUSTOM)
}, contact)
assertTrue(contact.impps[0].property.types.isEmpty())
assertNull(contact.impps[0].label)
}
@Test
fun testTypeCustom_WithLabel() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM)
put(Im.CUSTOM_PROTOCOL, "new-messenger")
put(Im.DATA, "messenger-id")
put(Im.TYPE, Im.TYPE_CUSTOM)
put(Im.LABEL, "New Messenger")
}, contact)
assertTrue(contact.impps[0].property.types.isEmpty())
assertEquals("New Messenger", contact.impps[0].label)
}
@Test
fun testType_Home() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM)
put(Im.CUSTOM_PROTOCOL, "new-messenger")
put(Im.DATA, "messenger-id")
put(Im.TYPE, Im.TYPE_HOME)
}, contact)
assertEquals(ImppType.HOME, contact.impps[0].property.types[0])
}
@Test
fun testType_Other() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM)
put(Im.CUSTOM_PROTOCOL, "new-messenger")
put(Im.DATA, "messenger-id")
put(Im.TYPE, Im.TYPE_OTHER)
}, contact)
assertTrue(contact.impps[0].property.types.isEmpty())
}
@Test
fun testType_Work() {
val contact = Contact()
ImHandler.handle(ContentValues().apply {
put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM)
put(Im.CUSTOM_PROTOCOL, "new-messenger")
put(Im.DATA, "messenger-id")
put(Im.TYPE, Im.TYPE_WORK)
}, contact)
assertEquals(ImppType.WORK, contact.impps[0].property.types[0])
}
}
|