File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed
main/java/com/x8bit/bitwarden/data/autofill/util
test/java/com/x8bit/bitwarden/data/autofill/util Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,12 @@ fun AutofillValue.extractMonthValue(
26
26
/* *
27
27
* Extract a text value from this [AutofillValue].
28
28
*/
29
- fun AutofillValue.extractTextValue (): String? = this
30
- .textValue
31
- .takeIf { it.isNotBlank() }
32
- ?.toString()
29
+ fun AutofillValue.extractTextValue (): String? =
30
+ if (this .isText) {
31
+ this
32
+ .textValue
33
+ .takeIf { it.isNotBlank() }
34
+ ?.toString()
35
+ } else {
36
+ null
37
+ }
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ class AutofillValueExtensionsTest {
79
79
fun `extractTextValue should return textValue when not blank` () {
80
80
// Setup
81
81
val autofillValue: AutofillValue = mockk {
82
+ every { isText } returns true
82
83
every { textValue } returns TEXT_VALUE
83
84
}
84
85
@@ -93,6 +94,7 @@ class AutofillValueExtensionsTest {
93
94
fun `extractTextValue should return null when not blank` () {
94
95
// Setup
95
96
val autofillValue: AutofillValue = mockk {
97
+ every { isText } returns true
96
98
every { textValue } returns " "
97
99
}
98
100
@@ -102,6 +104,20 @@ class AutofillValueExtensionsTest {
102
104
// Verify
103
105
assertNull(actual)
104
106
}
107
+
108
+ @Test
109
+ fun `extractTextValue should return null when not text` () {
110
+ // Setup
111
+ val autofillValue: AutofillValue = mockk {
112
+ every { isText } returns false
113
+ }
114
+
115
+ // Test
116
+ val actual = autofillValue.extractTextValue()
117
+
118
+ // Verify
119
+ assertNull(actual)
120
+ }
105
121
}
106
122
107
123
private const val LIST_VALUE : Int = 5
You can’t perform that action at this time.
0 commit comments