From 79b740b3054dd08154c97d13964e2002836aed89 Mon Sep 17 00:00:00 2001 From: dkhawk Date: Fri, 5 Apr 2024 11:10:03 -0600 Subject: [PATCH] Fix MountainsRepositoryTest broken test in starter branch --- .../data/local/MountainsRepositoryTest.kt | 17 ++++++++++---- .../data/local/MountainsRepositoryTest.kt | 23 ++++++++++++------- .../subjects/LocationSubject.kt | 2 +- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/solution/app/src/test/java/com/example/mountainmarkers/data/local/MountainsRepositoryTest.kt b/solution/app/src/test/java/com/example/mountainmarkers/data/local/MountainsRepositoryTest.kt index 0a39c64..67e880f 100644 --- a/solution/app/src/test/java/com/example/mountainmarkers/data/local/MountainsRepositoryTest.kt +++ b/solution/app/src/test/java/com/example/mountainmarkers/data/local/MountainsRepositoryTest.kt @@ -32,11 +32,18 @@ class MountainsRepositoryTest { assertThat(mountains).hasSize(143) - val sneffels = mountains.first { it.name == "Mount Sneffels" } + with(mountains.first { it.name == "Mount Sneffels" }) { + assertThat(name).isEqualTo("Mount Sneffels") + assertThat(elevation.value).isWithin(1.0e-6).of(4315.4) + assertThat(location).isWithin(3.m).of(38.0038, -107.7923) + assertThat(is14er()).isTrue() + } - assertThat(sneffels.name).isEqualTo("Mount Sneffels") - assertThat(sneffels.elevation.value).isWithin(1.0e-6).of(4315.4) - assertThat(sneffels.location).isWithin(3.m).of(38.0038, -107.7923) - assertThat(sneffels.is14er()).isTrue() + with(mountains.first { it.name.contains("\uD83D\uDC3B") }) { + assertThat(name).isEqualTo("Grizzly Peak \uD83D\uDC3B") + assertThat(elevation.value).isWithin(1.0e-6).of(4265.6) + assertThat(location).isWithin(3.m).of(39.0425, -106.5976) + assertThat(is14er()).isFalse() + } } } diff --git a/starter/app/src/test/java/com/example/mountainmarkers/data/local/MountainsRepositoryTest.kt b/starter/app/src/test/java/com/example/mountainmarkers/data/local/MountainsRepositoryTest.kt index 6857da3..75e53ae 100644 --- a/starter/app/src/test/java/com/example/mountainmarkers/data/local/MountainsRepositoryTest.kt +++ b/starter/app/src/test/java/com/example/mountainmarkers/data/local/MountainsRepositoryTest.kt @@ -15,9 +15,9 @@ package com.example.mountainmarkers.data.local import androidx.test.core.app.ApplicationProvider -import com.example.mountainmarkers.data.utils.m -import com.example.mountainsmap.subjects.assertThat import com.google.common.truth.Truth.assertThat +import com.example.mountainmarkers.data.utils.m +import com.example.mountainmarkers.subjects.assertThat import kotlinx.coroutines.runBlocking import org.junit.Test import org.junit.runner.RunWith @@ -28,15 +28,22 @@ class MountainsRepositoryTest { @Test fun canLoadMountainData() = runBlocking { val repo = MountainsRepository(ApplicationProvider.getApplicationContext()) - val mountains = repo.loadMountains() + val mountains = repo.loadMountains().value assertThat(mountains).hasSize(143) - val sneffels = mountains.first { it.name == "Mount Sneffels" } + with(mountains.first { it.name == "Mount Sneffels" }) { + assertThat(name).isEqualTo("Mount Sneffels") + assertThat(elevation.value).isWithin(1.0e-6).of(4315.4) + assertThat(location).isWithin(3.m).of(38.0038, -107.7923) + assertThat(is14er()).isTrue() + } - assertThat(sneffels.name).isEqualTo("Mount Sneffels") - assertThat(sneffels.elevation.value).isWithin(1.0e-6).of(4315.4) - assertThat(sneffels.location).isWithin(3.m).of(38.0038, -107.7923) - assertThat(sneffels.is14er()).isTrue() + with(mountains.first { it.name.contains("\uD83D\uDC3B") }) { + assertThat(name).isEqualTo("Grizzly Peak \uD83D\uDC3B") + assertThat(elevation.value).isWithin(1.0e-6).of(4265.6) + assertThat(location).isWithin(3.m).of(39.0425, -106.5976) + assertThat(is14er()).isFalse() + } } } diff --git a/starter/app/src/test/java/com/example/mountainmarkers/subjects/LocationSubject.kt b/starter/app/src/test/java/com/example/mountainmarkers/subjects/LocationSubject.kt index e1615fc..148f5c3 100644 --- a/starter/app/src/test/java/com/example/mountainmarkers/subjects/LocationSubject.kt +++ b/starter/app/src/test/java/com/example/mountainmarkers/subjects/LocationSubject.kt @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.example.mountainsmap.subjects +package com.example.mountainmarkers.subjects import com.google.common.truth.Subject import androidx.annotation.Nullable