From 7656572172e45d3591d646075ac69e679f4a027c Mon Sep 17 00:00:00 2001 From: mcarare <48995920+mcarare@users.noreply.github.com> Date: Mon, 22 Dec 2025 19:35:24 +0200 Subject: [PATCH] Add unit tests for `String.replace(Map)` extension function. --- app/build.gradle | 2 + .../reference/browser/ext/StringKtTest.kt | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 app/src/test/java/org/mozilla/reference/browser/ext/StringKtTest.kt diff --git a/app/build.gradle b/app/build.gradle index 96fde11e6..12a7d2a0f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -290,6 +290,8 @@ dependencies { implementation libs.mozilla.ui.tabcounter implementation libs.mozilla.ui.widgets + testImplementation libs.junit + androidTestImplementation libs.androidx.test.espresso.core androidTestImplementation libs.androidx.test.espresso.idling.resources constraints { diff --git a/app/src/test/java/org/mozilla/reference/browser/ext/StringKtTest.kt b/app/src/test/java/org/mozilla/reference/browser/ext/StringKtTest.kt new file mode 100644 index 000000000..020ebb053 --- /dev/null +++ b/app/src/test/java/org/mozilla/reference/browser/ext/StringKtTest.kt @@ -0,0 +1,45 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.reference.browser.ext + +import org.junit.Assert.assertEquals +import org.junit.Test + +class StringKtTest { + @Test + fun `replace should replace all keys with their corresponding values`() { + val input = "The quick brown fox jumps over the lazy dog" + val pairs = mapOf( + "quick" to "slow", + "brown" to "red", + "fox" to "cat", + "dog" to "mouse", + ) + + val result = input.replace(pairs) + + assertEquals("The slow red cat jumps over the lazy mouse", result) + } + + @Test + fun `replace should return the same string if the map is empty`() { + val input = "Hello world" + val pairs = emptyMap() + + val result = input.replace(pairs) + + assertEquals(input, result) + } + + @Test + fun `replace should handle keys that are not present in the string`() { + val input = "Hello world" + val pairs = mapOf("foo" to "bar") + + val result = input.replace(pairs) + + assertEquals("Hello world", result) + } +}