forked from GrapheneOS/Messaging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondaryUserMessageResolverTest.kt
More file actions
102 lines (85 loc) · 3.28 KB
/
Copy pathSecondaryUserMessageResolverTest.kt
File metadata and controls
102 lines (85 loc) · 3.28 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
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
package com.android.messaging.data.secondaryuser
import com.android.messaging.data.phone.formatter.PhoneNumberFormatter
import com.android.messaging.data.secondaryuser.model.SecondaryUserMessageInfo
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
internal class SecondaryUserMessageResolverTest {
private val contactNameLookup = mockk<SmsContactNameLookup>()
private val phoneNumberFormatter = mockk<PhoneNumberFormatter>()
private val resolver = SecondaryUserMessageResolverImpl(
contactNameLookup = contactNameLookup,
phoneNumberFormatter = phoneNumberFormatter,
)
@Test
fun resolve_contactFound_usesContactName() {
every { contactNameLookup.lookup("+15551234") } returns "Alice"
val info = resolver.resolve(address = "+15551234", body = "Hello there")
assertEquals(
SecondaryUserMessageInfo(sender = "Alice", body = "Hello there"),
info,
)
verify(exactly = 0) {
phoneNumberFormatter.formatForDisplay(any())
}
}
@Test
fun resolve_noMatchingContact_fallsBackToFormattedNumber() {
every { contactNameLookup.lookup("+15551234") } returns null
every { phoneNumberFormatter.formatForDisplay("+15551234") } returns "+1 555-1234"
val info = resolver.resolve(address = "+15551234", body = "Hello there")
assertEquals(
SecondaryUserMessageInfo(sender = "+1 555-1234", body = "Hello there"),
info,
)
}
@Test
fun resolve_blankContactName_fallsBackToFormattedNumber() {
every { contactNameLookup.lookup("+15551234") } returns ""
every { phoneNumberFormatter.formatForDisplay("+15551234") } returns "+1 555-1234"
val info = resolver.resolve(address = "+15551234", body = "Hello there")
assertEquals(
SecondaryUserMessageInfo(sender = "+1 555-1234", body = "Hello there"),
info,
)
}
@Test
fun resolve_shortAddress_usesFormattedAddress() {
every { contactNameLookup.lookup("123") } returns null
every { phoneNumberFormatter.formatForDisplay("123") } returns "123"
val info = resolver.resolve(address = "123", body = "Hello there")
assertEquals(
SecondaryUserMessageInfo(sender = "123", body = "Hello there"),
info,
)
}
@Test
fun resolve_nullBody_returnsNull() {
assertNull(resolver.resolve(address = "+15551234", body = null))
verifyNoSenderResolution()
}
@Test
fun resolve_emptyBody_returnsNull() {
assertNull(resolver.resolve(address = "+15551234", body = ""))
verifyNoSenderResolution()
}
@Test
fun resolve_nullAddress_returnsNull() {
assertNull(resolver.resolve(address = null, body = "Hello there"))
verifyNoSenderResolution()
}
@Test
fun resolve_emptyAddress_returnsNull() {
assertNull(resolver.resolve(address = "", body = "Hello there"))
verifyNoSenderResolution()
}
private fun verifyNoSenderResolution() {
verify(exactly = 0) {
contactNameLookup.lookup(any())
phoneNumberFormatter.formatForDisplay(any())
}
}
}