Skip to content

Commit e8af3ff

Browse files
committed
Add unit tests for String.replace(Map<String, String>) extension function.
1 parent b9665dd commit e8af3ff

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ dependencies {
290290
implementation libs.mozilla.ui.tabcounter
291291
implementation libs.mozilla.ui.widgets
292292

293+
testImplementation libs.junit
294+
293295
androidTestImplementation libs.androidx.test.espresso.core
294296
androidTestImplementation libs.androidx.test.espresso.idling.resources
295297
constraints {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package org.mozilla.reference.browser.ext
6+
7+
import org.junit.Assert.assertEquals
8+
import org.junit.Test
9+
10+
class StringKtTest {
11+
@Test
12+
fun `replace should replace all keys with their corresponding values`() {
13+
val input = "The quick brown fox jumps over the lazy dog"
14+
val pairs = mapOf(
15+
"quick" to "slow",
16+
"brown" to "red",
17+
"fox" to "cat",
18+
"dog" to "mouse",
19+
)
20+
21+
val result = input.replace(pairs)
22+
23+
assertEquals("The slow red cat jumps over the lazy mouse", result)
24+
}
25+
26+
@Test
27+
fun `replace should return the same string if the map is empty`() {
28+
val input = "Hello world"
29+
val pairs = emptyMap<String, String>()
30+
31+
val result = input.replace(pairs)
32+
33+
assertEquals(input, result)
34+
}
35+
36+
@Test
37+
fun `replace should handle keys that are not present in the string`() {
38+
val input = "Hello world"
39+
val pairs = mapOf("foo" to "bar")
40+
41+
val result = input.replace(pairs)
42+
43+
assertEquals("Hello world", result)
44+
}
45+
}

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ subprojects {
8888
afterEvaluate {
8989
if (it.hasProperty('android')) {
9090
jacoco {
91-
toolVersion = libs.versions.jacoco
91+
toolVersion = libs.versions.jacoco.get()
9292
}
9393

9494
android {
9595

9696
testOptions {
97+
9798
unitTests {
9899
includeAndroidResources = true
99100
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ktlint = "1.8.0"
4848

4949
# Third Party Testing
5050
hamcrest = "1.3"
51-
jacoco = "0.8.14"
51+
jacoco = "0.8.12"
5252
junit = "4.13.2"
5353
okhttp = "5.3.2"
5454
okio = "3.16.4"

0 commit comments

Comments
 (0)