Merge "Minor Refactor of PreferencesTest.kt" into androidx-main
diff --git a/datastore/datastore-preferences-core/src/commonTest/kotlin/androidx/datastore/preferences/core/PreferencesTest.kt b/datastore/datastore-preferences-core/src/commonTest/kotlin/androidx/datastore/preferences/core/PreferencesTest.kt
index c159b61..440b2a1 100644
--- a/datastore/datastore-preferences-core/src/commonTest/kotlin/androidx/datastore/preferences/core/PreferencesTest.kt
+++ b/datastore/datastore-preferences-core/src/commonTest/kotlin/androidx/datastore/preferences/core/PreferencesTest.kt
@@ -18,435 +18,438 @@
 
 import androidx.kruth.assertThat
 import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertNotEquals
-import kotlin.test.assertNull
-import kotlin.test.assertTrue
 
 class PreferencesTest {
 
     @Test
-    fun testBoolean() {
+    fun booleanPreferenceCanBeRetrieved() {
         val booleanKey = booleanPreferencesKey("boolean_key")
+        val preferences = preferencesOf(booleanKey to true)
 
-        val prefs = preferencesOf(booleanKey to true)
+        val booleanPreference = preferences[booleanKey]
 
-        assertTrue { booleanKey in prefs }
-        assertTrue(prefs[booleanKey]!!)
+        assertThat(booleanPreference).isTrue()
     }
 
     @Test
-    fun testBooleanNotSet() {
+    fun unsetBooleanPreferenceReturnsNull() {
         val booleanKey = booleanPreferencesKey("boolean_key")
+        val preferences = emptyPreferences()
 
-        assertNull(emptyPreferences()[booleanKey])
+        val booleanPreference = preferences[booleanKey]
+
+        assertThat(booleanPreference).isNull()
     }
 
     @Test
-    fun testFloat() {
+    fun floatPreferenceCanBeRetrieved() {
         val floatKey = floatPreferencesKey("float_key")
+        val preferences = preferencesOf(floatKey to 1.1f)
 
-        val prefs = preferencesOf(floatKey to 1.1f)
+        val floatPreference = preferences[floatKey]
 
-        assertTrue { floatKey in prefs }
-        assertEquals(1.1f, prefs[floatKey])
+        assertThat(floatPreference).isEqualTo(1.1f)
     }
 
     @Test
-    fun testFloatNotSet() {
+    fun unsetFloatPreferenceReturnsNull() {
         val floatKey = floatPreferencesKey("float_key")
-        assertNull(emptyPreferences()[floatKey])
+        val preferences = emptyPreferences()
+
+        val floatPreference = preferences[floatKey]
+
+        assertThat(floatPreference).isNull()
     }
 
     @Test
-    fun testDouble() {
+    fun doublePreferenceCanBeRetrieved() {
         val doubleKey = doublePreferencesKey("double_key")
+        val preferences = preferencesOf(doubleKey to Double.MAX_VALUE)
 
-        val prefs = preferencesOf(doubleKey to Double.MAX_VALUE)
+        val doublePreference = preferences[doubleKey]
 
-        assertTrue { doubleKey in prefs }
-        assertEquals(Double.MAX_VALUE, prefs[doubleKey])
+        assertThat(doublePreference).isEqualTo(Double.MAX_VALUE)
     }
 
     @Test
-    fun testDoubleNotSet() {
-        val doubleKey = doublePreferencesKey("double_key")
-        assertNull(emptyPreferences()[doubleKey])
+    fun unsetDoublePreferenceReturnsNull() {
+        val doubleKey = floatPreferencesKey("double_key")
+        val preferences = emptyPreferences()
+
+        val doublePreference = preferences[doubleKey]
+
+        assertThat(doublePreference).isNull()
     }
 
     @Test
-    fun testInt() {
+    fun intPreferenceCanBeRetrieved() {
         val intKey = intPreferencesKey("int_key")
+        val preferences = preferencesOf(intKey to 1)
 
-        val prefs = preferencesOf(intKey to 1)
+        val intPreference = preferences[intKey]
 
-        assertTrue { prefs.contains(intKey) }
-        assertEquals(1, prefs[intKey])
+        assertThat(intPreference).isEqualTo(1)
     }
 
     @Test
-    fun testIntNotSet() {
+    fun unsetIntPreferenceReturnsNull() {
         val intKey = intPreferencesKey("int_key")
-        assertNull(emptyPreferences()[intKey])
+        val preferences = emptyPreferences()
+
+        val intPreference = preferences[intKey]
+
+        assertThat(intPreference).isNull()
     }
 
     @Test
-    fun testLong() {
+    fun longPreferenceCanBeRetrieved() {
         val longKey = longPreferencesKey("long_key")
-
         val bigLong = 1L shr 50 // 2^50 > Int.MAX_VALUE
+        val preferences = preferencesOf(longKey to bigLong)
 
-        val prefs = preferencesOf(longKey to bigLong)
+        val longPreference = preferences[longKey]
 
-        assertTrue { prefs.contains(longKey) }
-        assertEquals(bigLong, prefs[longKey])
+        assertThat(longPreference).isEqualTo(bigLong)
     }
 
     @Test
-    fun testLongNotSet() {
+    fun unsetLongPreferenceReturnsNull() {
         val longKey = longPreferencesKey("long_key")
+        val preferences = emptyPreferences()
 
-        assertNull(emptyPreferences()[longKey])
+        val longPreference = preferences[longKey]
+
+        assertThat(longPreference).isNull()
     }
 
     @Test
-    fun testString() {
+    fun stringPreferenceCanBeRetrieved() {
         val stringKey = stringPreferencesKey("string_key")
+        val preferences = preferencesOf(stringKey to "string123")
 
-        val prefs = preferencesOf(stringKey to "string123")
+        val stringPreference = preferences[stringKey]
 
-        assertTrue { prefs.contains(stringKey) }
-        assertEquals("string123", prefs[stringKey])
+        assertThat(stringPreference).isEqualTo("string123")
     }
 
     @Test
-    fun testStringNotSet() {
+    fun unsetStringPreferenceReturnsNull() {
         val stringKey = stringPreferencesKey("string_key")
+        val preferences = emptyPreferences()
 
-        assertNull(emptyPreferences()[stringKey])
+        val stringPreference = preferences[stringKey]
+
+        assertThat(stringPreference).isNull()
     }
 
     @Test
-    fun testStringSet() {
+    fun stringSetPreferenceCanBeRetrieved() {
         val stringSetKey = stringSetPreferencesKey("string_set_key")
+        val preferences = preferencesOf(stringSetKey to setOf("string1", "string2", "string3"))
 
-        val prefs = preferencesOf(stringSetKey to setOf("string1", "string2", "string3"))
+        val stringSetPreference = preferences[stringSetKey]
 
-        assertTrue { prefs.contains(stringSetKey) }
-        assertEquals(setOf("string1", "string2", "string3"), prefs[stringSetKey])
+        assertThat(stringSetPreference).isEqualTo(setOf("string1", "string2", "string3"))
     }
 
     @Test
-    fun testStringSetNotSet() {
+    fun unsetStringSetPreferenceReturnsNull() {
         val stringSetKey = stringSetPreferencesKey("string_set_key")
+        val preferences = emptyPreferences()
 
-        assertNull(emptyPreferences()[stringSetKey])
+        val stringSetPreference = preferences[stringSetKey]
+
+        assertThat(stringSetPreference).isNull()
     }
 
     @Test
-    fun testByteArray() {
+    fun byteArrayPreferenceCanBeRetrieved() {
+        val byteArrayKey = byteArrayPreferencesKey("byte_array_key")
+        val preferences = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3, 4))
+
+        val byteArrayPreference = preferences[byteArrayKey]
+
+        assertThat(byteArrayPreference).isEqualTo(byteArrayOf(1, 2, 3, 4))
+    }
+
+    @Test
+    fun unsetByteArrayPreferenceReturnsNull() {
+        val byteArrayKey = byteArrayPreferencesKey("byte_array_key")
+        val preferences = emptyPreferences()
+
+        val byteArrayPreference = preferences[byteArrayKey]
+
+        assertThat(byteArrayPreference).isNull()
+    }
+
+    @Test
+    fun modifyingOriginalByteArrayDoesNotModifyInternalState() {
         val byteArrayKey = byteArrayPreferencesKey("byte_array_key")
         val byteArray = byteArrayOf(1, 2, 3, 4)
+        val preferences = preferencesOf(byteArrayKey to byteArray)
 
-        val prefs = preferencesOf(byteArrayKey to byteArray)
+        // modify the array passed into preferences.
+        byteArray[0] = 5
 
-        assertTrue { byteArrayKey in prefs }
-        assertTrue(byteArray.contentEquals(prefs[byteArrayKey]))
+        assertThat(byteArray).isEqualTo(byteArrayOf(5, 2, 3, 4))
+        assertThat(preferences[byteArrayKey]).isEqualTo(byteArrayOf(1, 2, 3, 4))
     }
 
     @Test
-    fun testByteArrayNotSet() {
-        val byteArrayKey = byteArrayPreferencesKey("byte_array_key")
-        assertNull(emptyPreferences()[byteArrayKey])
-    }
-
-    @Test
-    fun testModifyingOriginalByteArrayDoesntModifyInternalState() {
+    fun modifyingReturnedByteArrayDoesNotModifyInternalState() {
         val byteArrayKey = byteArrayPreferencesKey("byte_array_key")
         val byteArray = byteArrayOf(1, 2, 3, 4)
-        val prefs = preferencesOf(byteArrayKey to byteArray)
+        val preferences = preferencesOf(byteArrayKey to byteArray)
 
-        byteArray[0] = 5 // modify the array passed into preferences
-
-        assertTrue(byteArrayOf(5, 2, 3, 4).contentEquals(byteArray))
-        assertTrue(byteArrayOf(1, 2, 3, 4).contentEquals(prefs[byteArrayKey]))
-    }
-
-    @Test
-    fun testModifyingReturnedByteArrayDoesntModifyInternalState() {
-        val byteArrayKey = byteArrayPreferencesKey("byte_array_key")
-        val byteArray = byteArrayOf(1, 2, 3, 4)
-        val prefs = preferencesOf(byteArrayKey to byteArray)
-
-        val readPrefs = prefs[byteArrayKey]!!
+        val readPrefs = preferences[byteArrayKey]!!
         readPrefs[0] = 5
 
-        assertTrue(byteArrayOf(5, 2, 3, 4).contentEquals(readPrefs))
-        assertTrue(byteArrayOf(1, 2, 3, 4).contentEquals(prefs[byteArrayKey]))
+        assertThat(readPrefs).isEqualTo(byteArrayOf(5, 2, 3, 4))
+        assertThat(preferences[byteArrayKey]).isEqualTo(byteArrayOf(1, 2, 3, 4))
     }
 
     @Test
-    fun testGetAll() {
+    fun asMapReturnsAllPreferences() {
         val intKey = intPreferencesKey("int_key")
         val stringSetKey = stringSetPreferencesKey("string_set_key")
-
         val prefs = preferencesOf(intKey to 123, stringSetKey to setOf("1", "2", "3"))
 
         val allPreferences: Map<Preferences.Key<*>, Any> = prefs.asMap()
-        assertEquals(2, allPreferences.size)
 
-        assertEquals(123, allPreferences[intKey])
-        assertEquals(setOf("1", "2", "3"), (allPreferences[stringSetKey]))
+        assertThat(allPreferences)
+            .containsExactly(Pair(intKey, 123), Pair(stringSetKey, setOf("1", "2", "3")))
     }
 
     @Test
-    fun testMutablePreferencesClear() {
+    fun clearRemovesAllPreferencesFromMutablePreferences() {
         val intKey = intPreferencesKey("int_key")
+        val preferences = preferencesOf(intKey to 123)
 
-        val prefsWithInt = preferencesOf(intKey to 123)
+        val clearedPreferences =
+            preferences.toMutablePreferences().apply { clear() }.toPreferences()
 
-        val emptyPrefs = prefsWithInt.toMutablePreferences().apply { clear() }.toPreferences()
-
-        assertEquals(emptyPreferences(), emptyPrefs)
+        assertThat(clearedPreferences).isEqualTo(emptyPreferences())
     }
 
     @Test
-    fun testMutablePreferencesRemove() {
+    fun removeRemovesPreferenceKey() {
         val intKey = intPreferencesKey("int_key")
+        val preferences = preferencesOf(intKey to 123)
 
-        val prefsWithInt = preferencesOf(intKey to 123)
+        // Remove using function.
+        val preferencesAfterRemove1 =
+            preferences.toMutablePreferences().apply { remove(intKey) }.toPreferences()
 
-        val emptyPrefs =
-            prefsWithInt.toMutablePreferences().apply { remove(intKey) }.toPreferences()
+        assertThat(preferencesAfterRemove1).isEqualTo(emptyPreferences())
 
-        assertEquals(emptyPreferences(), emptyPrefs)
+        // Remove using overloaded operator.
+        val preferencesAfterRemove2 =
+            preferences.toMutablePreferences().also { it -= intKey }.toPreferences()
 
-        val emptyPrefs2 = prefsWithInt.toMutablePreferences()
-        emptyPrefs2 -= intKey
-
-        assertEquals(emptyPreferences(), emptyPrefs2)
+        assertThat(preferencesAfterRemove2).isEqualTo(emptyPreferences())
     }
 
     @Test
-    fun testBuilderPublicConstructor() {
-        val emptyPrefs = mutablePreferencesOf().toPreferences()
+    fun mutablePreferencesPublicConstructor() {
+        val preferences = mutablePreferencesOf().toPreferences()
 
-        assertEquals(emptyPreferences(), emptyPrefs)
+        assertThat(preferences).isEqualTo(emptyPreferences())
     }
 
     @Test
-    fun testEqualsDifferentInstances() {
+    fun equalsReturnsTrueForDifferentInstancesWithSameValues() {
         val intKey1 = intPreferencesKey("int_key1")
-
         val prefs1 = preferencesOf(intKey1 to 123)
         val prefs2 = preferencesOf(intKey1 to 123)
 
-        assertEquals(prefs1, prefs2)
+        assertThat(prefs1).isEqualTo(prefs2)
     }
 
     @Test
-    fun testNotEqualsDifferentKeys() {
+    fun equalsReturnsFalseForDifferentKeys() {
         val intKey1 = intPreferencesKey("int_key1")
         val intKey2 = intPreferencesKey("int_key2")
-
         val prefs1 = preferencesOf(intKey1 to 123)
         val prefs2 = preferencesOf(intKey2 to 123)
 
-        assertNotEquals(prefs1, prefs2)
+        assertThat(prefs1).isNotEqualTo(prefs2)
     }
 
     @Test
-    fun testNotEqualsDifferentValues() {
+    fun equalsReturnsFalseForDifferentValues() {
         val intKey1 = intPreferencesKey("int_key1")
-
         val prefs1 = preferencesOf(intKey1 to 123)
         val prefs2 = preferencesOf(intKey1 to 999)
 
-        assertNotEquals(prefs1, prefs2)
+        assertThat(prefs1).isNotEqualTo(prefs2)
     }
 
     @Test
-    fun testNotEqualsDifferentStringSets() {
+    fun equalsReturnsFalseForDifferentStringSets() {
         val stringSetKey = stringSetPreferencesKey("string_set")
-
         val prefs1 = preferencesOf(stringSetKey to setOf("1"))
         val prefs2 = preferencesOf(stringSetKey to setOf())
 
-        assertNotEquals(prefs1, prefs2)
+        assertThat(prefs1).isNotEqualTo(prefs2)
     }
 
     @Test
-    fun testEqualsByteArrayAndOther() {
+    fun equalsReturnsTrueForByteArrayAndOtherWithSameValues() {
         val byteArrayKey = byteArrayPreferencesKey("byte_array")
         val intKey = intPreferencesKey("int_key")
-
         val prefs1 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3), intKey to 1)
         val prefs2 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3), intKey to 1)
 
-        assertEquals(prefs1, prefs2)
+        assertThat(prefs1).isEqualTo(prefs2)
     }
 
     @Test
-    fun testNotEqualsByteArrayAndOther() {
+    fun equalsReturnsFalseForByteArrayAndOtherWithDifferentValues() {
         val byteArrayKey = byteArrayPreferencesKey("byte_array")
         val intKey = intPreferencesKey("int_key")
-
         val prefs1 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3), intKey to 1)
         val prefs2 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 4), intKey to 1)
 
-        assertNotEquals(prefs1, prefs2)
+        assertThat(prefs1).isNotEqualTo(prefs2)
     }
 
     @Test
-    fun testEqualsSameByteArrays() {
+    fun equalsReturnsTrueForSameByteArrays() {
         val byteArrayKey = byteArrayPreferencesKey("byte_array")
-
         val prefs1 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3))
         val prefs2 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3))
 
-        assertEquals(prefs1, prefs2)
+        assertThat(prefs1).isEqualTo(prefs2)
     }
 
     @Test
-    fun testNotEqualsDifferentByteArrays() {
+    fun equalsReturnsFalseForDifferentByteArrays() {
         val byteArrayKey = byteArrayPreferencesKey("byte_array")
-
         val prefs1 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3))
         val prefs2 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 4))
 
-        assertNotEquals(prefs1, prefs2)
+        assertThat(prefs1).isNotEqualTo(prefs2)
     }
 
     @Test
-    fun testByteArrayCreatesHashCodeBasedOnContents() {
+    fun hashCodeIsSameForSameContent() {
         val byteArrayKey = byteArrayPreferencesKey("byte_array_key")
-
-        val prefs = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3, 4))
+        val prefs1 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3, 4))
         val prefs2 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3, 4))
         val prefs3 = preferencesOf(byteArrayKey to byteArrayOf(1, 2, 3, 5))
 
-        assertEquals(prefs.hashCode(), prefs2.hashCode())
-        assertNotEquals(prefs.hashCode(), prefs3.hashCode())
+        val hashCode1 = prefs1.hashCode()
+        val hashCode2 = prefs2.hashCode()
+        val hashCode3 = prefs3.hashCode()
+
+        assertThat(hashCode1).isEqualTo(hashCode2)
+        assertThat(hashCode1).isNotEqualTo(hashCode3)
     }
 
     @Test
-    fun testToPreferences_retainsAllKeys() {
+    fun toPreferencesRetainsAllKeys() {
         val intKey1 = intPreferencesKey("int_key1")
         val intKey2 = intPreferencesKey("int_key2")
-        val prefs = preferencesOf(intKey1 to 1, intKey2 to 2)
-        val toPrefs = prefs.toPreferences()
-        assertEquals(2, toPrefs.asMap().size)
-        assertEquals(1, prefs[intKey1])
-        assertEquals(2, prefs[intKey2])
+        val preferences = preferencesOf(intKey1 to 1, intKey2 to 2)
+
+        val toPrefs = preferences.toPreferences()
+
+        assertThat(toPrefs.asMap()).containsExactly(Pair(intKey1, 1), Pair(intKey2, 2))
 
         val mutablePreferences = preferencesOf(intKey1 to 1, intKey2 to 2)
+
         val mutableToPrefs = mutablePreferences.toPreferences()
-        assertEquals(2, mutableToPrefs.asMap().size)
-        assertEquals(1, prefs[intKey1])
-        assertEquals(2, prefs[intKey2])
+
+        assertThat(mutableToPrefs.asMap()).containsExactly(Pair(intKey1, 1), Pair(intKey2, 2))
     }
 
     @Test
-    fun testToMutablePreferences_retainsAllKeys() {
+    fun toMutablePreferencesRetainsAllKeys() {
         val intKey1 = intPreferencesKey("int_key1")
         val intKey2 = intPreferencesKey("int_key2")
         val prefs = preferencesOf(intKey1 to 1, intKey2 to 2)
+
         val toPrefs = prefs.toMutablePreferences()
-        assertEquals(2, toPrefs.asMap().size)
-        assertEquals(1, prefs[intKey1])
-        assertEquals(2, prefs[intKey2])
+
+        assertThat(toPrefs.asMap()).containsExactly(Pair(intKey1, 1), Pair(intKey2, 2))
 
         val mutablePreferences = preferencesOf(intKey1 to 1, intKey2 to 2)
+
         val mutableToPrefs = mutablePreferences.toMutablePreferences()
-        assertEquals(2, mutableToPrefs.asMap().size)
-        assertEquals(1, prefs[intKey1])
-        assertEquals(2, prefs[intKey2])
+
+        assertThat(mutableToPrefs.asMap()).containsExactly(Pair(intKey1, 1), Pair(intKey2, 2))
     }
 
     @Test
-    fun testToMutablePreferences_doesntMutateOriginal() {
+    fun toMutablePreferencesDoesNotMutateOriginal() {
         val intKey1 = intPreferencesKey("int_key1")
         val intKey2 = intPreferencesKey("int_key2")
         val prefs = mutablePreferencesOf(intKey1 to 1, intKey2 to 2)
-        val toPrefs = prefs.toMutablePreferences()
-        toPrefs[intKey1] = 12903819
-        assertEquals(1, prefs[intKey1])
-
         val mutablePreferences = preferencesOf(intKey1 to 1, intKey2 to 2)
+        val toPrefs = prefs.toMutablePreferences()
         val mutableToPrefs = mutablePreferences.toMutablePreferences()
+
+        toPrefs[intKey1] = 12903819
         mutableToPrefs[intKey1] = 12903819
-        assertEquals(1, prefs[intKey1])
+
+        assertThat(prefs[intKey1]).isEqualTo(1)
+        assertThat(mutablePreferences[intKey1]).isEqualTo(1)
     }
 
     @Test
     fun clearPreferencesWithinCopyBlock() {
-        // Arrange.
         val key = intPreferencesKey("key")
         val prefsWithInt = preferencesOf(key to 123)
 
-        // Act.
         val resultingPrefs = prefsWithInt.copy { it.clear() }
 
-        // Assert.
         assertThat(resultingPrefs.asMap()).isEmpty()
     }
 
     @Test
     fun removeItemWithinCopyBlock() {
-        // Arrange.
         val key1 = intPreferencesKey("key1")
         val key2 = intPreferencesKey("key2")
         val key3 = intPreferencesKey("key3")
         val preferences = preferencesOf(key1 to 123, key2 to 456, key3 to 789)
 
-        // Act.
         val copiedPreferences = preferences.copy { it.remove(key2) }
 
-        // Assert.
         assertThat(copiedPreferences.asMap()).containsExactly(Pair(key1, 123), Pair(key3, 789))
     }
 
     @Test
     fun removeOnlyItemWithinCopyBlock() {
-        // Arrange.
         val intKey = intPreferencesKey("key")
         val prefsWithInt = preferencesOf(intKey to 123)
 
-        // Act.
         val copiedPreferences = prefsWithInt.copy { it.remove(intKey) }
 
-        // Assert.
         assertThat(copiedPreferences.asMap()).isEmpty()
     }
 
     @Test
     fun copyRetainsAllKeys() {
-        // Arrange.
         val key1 = intPreferencesKey("key1")
         val key2 = intPreferencesKey("key2")
         val key3 = intPreferencesKey("key3")
         val preferences = preferencesOf(key1 to 123, key2 to 456, key3 to 789)
 
-        // Act.
         val copiedPreferences = preferences.copy {}
 
-        // Assert.
         assertThat(copiedPreferences.asMap())
             .containsExactly(Pair(key1, 123), Pair(key2, 456), Pair(key3, 789))
     }
 
     @Test
-    fun copyPreferences_doesNotMutateOriginal() {
-        // Arrange.
+    fun copyDoesNotMutateOriginal() {
         val key1 = intPreferencesKey("key1")
         val key2 = intPreferencesKey("key2")
         val key3 = intPreferencesKey("key3")
         val preferences = preferencesOf(key1 to 123, key2 to 456, key3 to 789)
 
-        // Act.
         val copiedPreferences = preferences.copy { pref -> pref[key2] = 100 }
 
-        // Assert.
         assertThat(preferences.asMap())
             .containsExactly(Pair(key1, 123), Pair(key2, 456), Pair(key3, 789))
         assertThat(copiedPreferences.asMap())
@@ -454,43 +457,36 @@
     }
 
     @Test
-    fun testToString() {
-        val intKey = intPreferencesKey("int_key")
-        val booleanKey = booleanPreferencesKey("boolean_key")
-        val floatKey = floatPreferencesKey("float_key")
-        val doubleKey = doublePreferencesKey("double_key")
-        val stringKey = stringPreferencesKey("string_key")
-        val stringSetKey = stringSetPreferencesKey("string_set_key")
-        val longKey = longPreferencesKey("long_key")
-        val byteArrayKey = byteArrayPreferencesKey("byte_array_key")
-
-        val intActual = 123
-        val booleanActual = false
-        val floatActual = 3.14f
-        val doubleActual = 3.1415
-        val stringActual = "abc"
-        val stringSetActual = setOf("1", "2", "3")
-        val longActual = 10000000000L
-        val byteArrayActual = byteArrayOf(1, 2, 3, 4)
-
-        val prefs =
+    fun toStringReturnsCorrectStringRepresentation() {
+        val preferences =
             preferencesOf(
-                intKey to intActual,
-                booleanKey to booleanActual,
-                floatKey to floatActual,
-                doubleKey to doubleActual,
-                stringKey to stringActual,
-                stringSetKey to stringSetActual,
-                longKey to longActual,
-                byteArrayKey to byteArrayActual,
+                intPreferencesKey("int_key") to 123,
+                booleanPreferencesKey("boolean_key") to false,
+                floatPreferencesKey("float_key") to 3.14f,
+                doublePreferencesKey("double_key") to 3.1415,
+                stringPreferencesKey("string_key") to "abc",
+                stringSetPreferencesKey("string_set_key") to setOf("1", "2", "3"),
+                longPreferencesKey("long_key") to 10000000000L,
+                byteArrayPreferencesKey("byte_array_key") to byteArrayOf(1, 2, 3, 4),
             )
-        assertEquals(prefs[intKey], intActual)
-        assertEquals(prefs[booleanKey], booleanActual)
-        assertEquals(prefs[floatKey], floatActual)
-        assertEquals(prefs[doubleKey], doubleActual)
-        assertEquals(prefs[stringKey], stringActual)
-        assertEquals(prefs[stringSetKey], stringSetActual)
-        assertEquals(prefs[longKey], longActual)
-        assertTrue(prefs[byteArrayKey].contentEquals(byteArrayActual))
+
+        val stringValue = preferences.toString()
+
+        assertThat(stringValue)
+            .isEqualTo(
+                """
+            {
+              int_key = 123,
+              boolean_key = false,
+              float_key = 3.14,
+              double_key = 3.1415,
+              string_key = abc,
+              string_set_key = [1, 2, 3],
+              long_key = 10000000000,
+              byte_array_key = [1, 2, 3, 4]
+            }
+        """
+                    .trimIndent()
+            )
     }
 }