diff --git a/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt b/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt index 91dbd418..1392e733 100644 --- a/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt +++ b/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt @@ -26,7 +26,6 @@ import android.widget.Toast import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.graphics.Insets import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat @@ -44,10 +43,14 @@ import com.google.maps.android.collections.GroundOverlayManager import com.google.maps.android.collections.MarkerManager import com.google.maps.android.collections.PolygonManager import com.google.maps.android.collections.PolylineManager -import com.google.maps.android.data.Renderer.ImagesCache import com.google.maps.android.data.geojson.GeoJsonLineStringStyle import com.google.maps.android.data.geojson.GeoJsonPolygonStyle -import com.google.maps.android.ktx.* +import com.google.maps.android.ktx.awaitAnimateCamera +import com.google.maps.android.ktx.awaitMap +import com.google.maps.android.ktx.awaitMapLoad +import com.google.maps.android.ktx.awaitSnapshot +import com.google.maps.android.ktx.cameraIdleEvents +import com.google.maps.android.ktx.cameraMoveStartedEvents import com.google.maps.android.ktx.demo.io.MyItemReader import com.google.maps.android.ktx.demo.model.CacheViewModel import com.google.maps.android.ktx.demo.model.MyItem diff --git a/app/src/main/java/com/google/maps/android/ktx/demo/io/MyItemReader.kt b/app/src/main/java/com/google/maps/android/ktx/demo/io/MyItemReader.kt index 5cdaa8d3..2be2f8ad 100644 --- a/app/src/main/java/com/google/maps/android/ktx/demo/io/MyItemReader.kt +++ b/app/src/main/java/com/google/maps/android/ktx/demo/io/MyItemReader.kt @@ -21,7 +21,7 @@ import com.google.maps.android.ktx.demo.model.MyItem import org.json.JSONArray import org.json.JSONException import java.io.InputStream -import java.util.* +import java.util.Scanner /** * Helper class to read in cluster items from a resource diff --git a/build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt b/build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt index 633760e6..2fdc51c8 100644 --- a/build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt @@ -3,9 +3,11 @@ import com.vanniktech.maven.publish.AndroidSingleVariantLibrary import com.vanniktech.maven.publish.MavenPublishBaseExtension import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.* import org.gradle.testing.jacoco.plugins.JacocoPluginExtension import org.gradle.api.tasks.testing.Test +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.withType import org.gradle.testing.jacoco.plugins.JacocoTaskExtension class PublishingConventionPlugin : Plugin { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 29d0222b..793ac18f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -28,6 +28,7 @@ junit = "4.13.2" mockito = "5.21.0" mockitoInline = "5.2.0" mockitoKotlin = "2.2.0" +truth = "1.4.5" # --- Gradle Plugins --- # Versions for Gradle plugins used in the build process. @@ -68,6 +69,7 @@ junit = { group = "junit", name = "junit", version.ref = "junit" } mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" } mockito-inline = { group = "org.mockito", name = "mockito-inline", version.ref = "mockitoInline" } mockito-kotlin = { group = "com.nhaarman.mockitokotlin2", name = "mockito-kotlin", version.ref = "mockitoKotlin" } +truth = { group = "com.google.truth", name = "truth", version.ref = "truth" } # --- Gradle --- android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" } diff --git a/maps-ktx/build.gradle.kts b/maps-ktx/build.gradle.kts index 642d3974..664359db 100644 --- a/maps-ktx/build.gradle.kts +++ b/maps-ktx/build.gradle.kts @@ -68,6 +68,7 @@ dependencies { testImplementation(libs.mockito.core) testImplementation(libs.mockito.kotlin) testImplementation(libs.mockito.inline) + testImplementation(libs.truth) testImplementation(libs.kotlinx.coroutines.test) } diff --git a/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt b/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt index 495a058b..61e5a6f3 100644 --- a/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt +++ b/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt @@ -23,8 +23,27 @@ import androidx.annotation.IntDef import com.google.android.gms.maps.CameraUpdate import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.GoogleMapOptions -import com.google.android.gms.maps.model.* -import com.google.maps.android.ktx.model.* +import com.google.android.gms.maps.model.Circle +import com.google.android.gms.maps.model.CircleOptions +import com.google.android.gms.maps.model.GroundOverlay +import com.google.android.gms.maps.model.GroundOverlayOptions +import com.google.android.gms.maps.model.IndoorBuilding +import com.google.android.gms.maps.model.LatLng +import com.google.android.gms.maps.model.Marker +import com.google.android.gms.maps.model.MarkerOptions +import com.google.android.gms.maps.model.PointOfInterest +import com.google.android.gms.maps.model.Polygon +import com.google.android.gms.maps.model.PolygonOptions +import com.google.android.gms.maps.model.Polyline +import com.google.android.gms.maps.model.PolylineOptions +import com.google.android.gms.maps.model.TileOverlay +import com.google.android.gms.maps.model.TileOverlayOptions +import com.google.maps.android.ktx.model.circleOptions +import com.google.maps.android.ktx.model.groundOverlayOptions +import com.google.maps.android.ktx.model.markerOptions +import com.google.maps.android.ktx.model.polygonOptions +import com.google.maps.android.ktx.model.polylineOptions +import com.google.maps.android.ktx.model.tileOverlayOptions import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/GoogleMapTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/GoogleMapTest.kt index 0aa3af3b..ff982608 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/GoogleMapTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/GoogleMapTest.kt @@ -20,7 +20,7 @@ import org.mockito.Mock import org.mockito.Mockito.verify import org.mockito.Mockito import org.mockito.junit.MockitoJUnitRunner -import org.junit.Assert.assertNotNull +import com.google.common.truth.Truth.assertThat import org.junit.After import org.junit.Before import org.mockito.MockedStatic @@ -65,7 +65,7 @@ public class GoogleMapTest { public fun testCameraIdleEvents(): Unit = runTest { val job = launch { val event = googleMap.cameraIdleEvents().first() - assertNotNull(event) + assertThat(event).isNotNull() } advanceUntilIdle() verify(googleMap).setOnCameraIdleListener(cameraIdleListener.capture()) diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/CameraPositionTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/CameraPositionTest.kt index 5e3f3185..7db6ba53 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/CameraPositionTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/CameraPositionTest.kt @@ -18,7 +18,7 @@ package com.google.maps.android.ktx.model import com.google.android.gms.maps.model.LatLng -import org.junit.Assert.assertEquals +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class CameraPositionTest { @@ -31,9 +31,9 @@ internal class CameraPositionTest { tilt(1f) zoom(12f) } - assertEquals(1f, cameraPosition.bearing, 1e-6f) - assertEquals(LatLng(1.0, 2.0), cameraPosition.target) - assertEquals(1f, cameraPosition.tilt, 1e-6f) - assertEquals(12f, cameraPosition.zoom, 1e-6f) + assertThat(cameraPosition.bearing).isWithin(1e-6f).of(1f) + assertThat(cameraPosition.target).isEqualTo(LatLng(1.0, 2.0)) + assertThat(cameraPosition.tilt).isWithin(1e-6f).of(1f) + assertThat(cameraPosition.zoom).isWithin(1e-6f).of(12f) } } \ No newline at end of file diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/CircleOptionsTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/CircleOptionsTest.kt index e887abf3..6e5a8fc1 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/CircleOptionsTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/CircleOptionsTest.kt @@ -18,8 +18,7 @@ package com.google.maps.android.ktx.model import com.google.android.gms.maps.model.LatLng -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class CircleOptionsTest { @@ -36,13 +35,13 @@ internal class CircleOptionsTest { visible(true) zIndex(1f) } - assertEquals(LatLng(0.0, 0.0), circleOptions.center) - assertTrue(circleOptions.isClickable) - assertEquals(0, circleOptions.fillColor) - assertEquals(1.23, circleOptions.radius, 1e-6) - assertEquals(1, circleOptions.strokeColor) - assertEquals(2f, circleOptions.strokeWidth) - assertTrue(circleOptions.isVisible) - assertEquals(1f, circleOptions.zIndex, 1e-6f) + assertThat(circleOptions.center).isEqualTo(LatLng(0.0, 0.0)) + assertThat(circleOptions.isClickable).isTrue() + assertThat(circleOptions.fillColor).isEqualTo(0) + assertThat(circleOptions.radius).isWithin(1e-6).of(1.23) + assertThat(circleOptions.strokeColor).isEqualTo(1) + assertThat(circleOptions.strokeWidth).isEqualTo(2f) + assertThat(circleOptions.isVisible).isTrue() + assertThat(circleOptions.zIndex).isWithin(1e-6f).of(1f) } } diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/GroundOverlayOptionsTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/GroundOverlayOptionsTest.kt index f7eaf707..1038d3c0 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/GroundOverlayOptionsTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/GroundOverlayOptionsTest.kt @@ -18,9 +18,8 @@ package com.google.maps.android.ktx.model import com.google.android.gms.maps.model.BitmapDescriptor +import com.google.common.truth.Truth.assertThat import com.nhaarman.mockitokotlin2.mock -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue import org.junit.Test internal class GroundOverlayOptionsTest { @@ -35,10 +34,10 @@ internal class GroundOverlayOptionsTest { transparency(0.5f) visible(true) } - assertEquals(descriptor, groundOverlayOptions.image) - assertEquals(1f, groundOverlayOptions.bearing, 1e-6f) - assertTrue(groundOverlayOptions.isClickable) - assertEquals(0.5f, groundOverlayOptions.transparency, 1e-6f) - assertTrue(groundOverlayOptions.isVisible) + assertThat(groundOverlayOptions.image).isEqualTo(descriptor) + assertThat(groundOverlayOptions.bearing).isWithin(1e-6f).of(1f) + assertThat(groundOverlayOptions.isClickable).isTrue() + assertThat(groundOverlayOptions.transparency).isWithin(1e-6f).of(0.5f) + assertThat(groundOverlayOptions.isVisible).isTrue() } } \ No newline at end of file diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/MarkerOptionsTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/MarkerOptionsTest.kt index 7896d491..63696d92 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/MarkerOptionsTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/MarkerOptionsTest.kt @@ -18,9 +18,7 @@ package com.google.maps.android.ktx.model import com.google.android.gms.maps.model.LatLng -import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class MarkerOptionsTest { @@ -36,12 +34,12 @@ internal class MarkerOptionsTest { snippet("Snippet") visible(true) } - assertEquals(LatLng(1.0, 2.0), markerOptions.position) - assertEquals(0.5f, markerOptions.alpha, 1e-6f) - assertFalse(markerOptions.isDraggable) - assertTrue(markerOptions.isFlat) - assertEquals("Test", markerOptions.title) - assertEquals("Snippet", markerOptions.snippet) - assertTrue(markerOptions.isVisible) + assertThat(markerOptions.position).isEqualTo(LatLng(1.0, 2.0)) + assertThat(markerOptions.alpha).isWithin(1e-6f).of(0.5f) + assertThat(markerOptions.isDraggable).isFalse() + assertThat(markerOptions.isFlat).isTrue() + assertThat(markerOptions.title).isEqualTo("Test") + assertThat(markerOptions.snippet).isEqualTo("Snippet") + assertThat(markerOptions.isVisible).isTrue() } } diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/PolygonOptionsTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/PolygonOptionsTest.kt index 734afb8e..e6117a91 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/PolygonOptionsTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/PolygonOptionsTest.kt @@ -19,7 +19,7 @@ package com.google.maps.android.ktx.model import android.graphics.Color import com.google.android.gms.maps.model.LatLng -import org.junit.Assert.assertEquals +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class PolygonOptionsTest { @@ -31,8 +31,8 @@ internal class PolygonOptionsTest { strokeColor(Color.BLACK) add(LatLng(1.0, 2.0)) } - assertEquals(1.0f, polygonOptions.strokeWidth, 1e-6f) - assertEquals(Color.BLACK, polygonOptions.strokeColor) - assertEquals(listOf(LatLng(1.0, 2.0)), polygonOptions.points) + assertThat(polygonOptions.strokeWidth).isWithin(1e-6f).of(1.0f) + assertThat(polygonOptions.strokeColor).isEqualTo(Color.BLACK) + assertThat(polygonOptions.points).containsExactly(LatLng(1.0, 2.0)) } } \ No newline at end of file diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/PolylineOptionsTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/PolylineOptionsTest.kt index 1b31e3cf..b1e1f13a 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/PolylineOptionsTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/PolylineOptionsTest.kt @@ -18,8 +18,7 @@ package com.google.maps.android.ktx.model import com.google.android.gms.maps.model.LatLng -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class PolylineOptionsTest { @@ -33,10 +32,10 @@ internal class PolylineOptionsTest { geodesic(true) width(1f) } - assertEquals(listOf(LatLng(1.0, 2.0)), polylineOptions.points) - assertTrue(polylineOptions.isClickable) - assertEquals(0, polylineOptions.color) - assertTrue(polylineOptions.isGeodesic) - assertEquals(1f, polylineOptions.width, 1e-6f) + assertThat(polylineOptions.points).containsExactly(LatLng(1.0, 2.0)) + assertThat(polylineOptions.isClickable).isTrue() + assertThat(polylineOptions.color).isEqualTo(0) + assertThat(polylineOptions.isGeodesic).isTrue() + assertThat(polylineOptions.width).isWithin(1e-6f).of(1f) } } \ No newline at end of file diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/StreetViewPanoramaCameraTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/StreetViewPanoramaCameraTest.kt index d3f66567..b0d64f68 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/StreetViewPanoramaCameraTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/StreetViewPanoramaCameraTest.kt @@ -17,7 +17,7 @@ package com.google.maps.android.ktx.model -import org.junit.Assert.assertEquals +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class StreetViewPanoramaCameraTest { @@ -29,8 +29,8 @@ internal class StreetViewPanoramaCameraTest { tilt(20f) zoom(2f) } - assertEquals(1f, camera.bearing, 1e-6f) - assertEquals(20f, camera.tilt, 1e-6f) - assertEquals(2f, camera.zoom, 1e-6f) + assertThat(camera.bearing).isWithin(1e-6f).of(1f) + assertThat(camera.tilt).isWithin(1e-6f).of(20f) + assertThat(camera.zoom).isWithin(1e-6f).of(2f) } } \ No newline at end of file diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/StreetViewPanoramaOrientationTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/StreetViewPanoramaOrientationTest.kt index 2229cc6c..93775461 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/StreetViewPanoramaOrientationTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/StreetViewPanoramaOrientationTest.kt @@ -17,7 +17,7 @@ package com.google.maps.android.ktx.model -import org.junit.Assert.assertEquals +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class StreetViewPanoramaOrientationTest { @@ -28,7 +28,7 @@ internal class StreetViewPanoramaOrientationTest { bearing(1f) tilt(20f) } - assertEquals(1f, orientation.bearing, 1e-6f) - assertEquals(20f, orientation.tilt, 1e-6f) + assertThat(orientation.bearing).isWithin(1e-6f).of(1f) + assertThat(orientation.tilt).isWithin(1e-6f).of(20f) } } diff --git a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/TileOverlayOptionsTest.kt b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/TileOverlayOptionsTest.kt index 350a1914..2ff7b81a 100644 --- a/maps-ktx/src/test/java/com/google/maps/android/ktx/model/TileOverlayOptionsTest.kt +++ b/maps-ktx/src/test/java/com/google/maps/android/ktx/model/TileOverlayOptionsTest.kt @@ -17,9 +17,7 @@ package com.google.maps.android.ktx.model -import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class TileOverlayOptionsTest { @@ -32,9 +30,9 @@ internal class TileOverlayOptionsTest { visible(false) zIndex(1f) } - assertTrue(tileOverlayOptions.fadeIn) - assertFalse(tileOverlayOptions.isVisible) - assertEquals(0.5f, tileOverlayOptions.transparency, 1e-6f) - assertEquals(1f, tileOverlayOptions.zIndex, 1e-6f) + assertThat(tileOverlayOptions.fadeIn).isTrue() + assertThat(tileOverlayOptions.isVisible).isFalse() + assertThat(tileOverlayOptions.transparency).isWithin(1e-6f).of(0.5f) + assertThat(tileOverlayOptions.zIndex).isWithin(1e-6f).of(1f) } } \ No newline at end of file diff --git a/maps-utils-ktx/build.gradle.kts b/maps-utils-ktx/build.gradle.kts index 475aeabf..5fbff0f6 100644 --- a/maps-utils-ktx/build.gradle.kts +++ b/maps-utils-ktx/build.gradle.kts @@ -65,4 +65,5 @@ dependencies { testImplementation(libs.mockito.core) testImplementation(libs.mockito.kotlin) testImplementation(libs.mockito.inline) + testImplementation(libs.truth) } diff --git a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/LatLngTest.kt b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/LatLngTest.kt index f66c521f..371ab751 100644 --- a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/LatLngTest.kt +++ b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/LatLngTest.kt @@ -18,7 +18,7 @@ package com.google.maps.android.ktx.utils import com.google.android.gms.maps.model.LatLng -import org.junit.Assert.* +import com.google.common.truth.Truth.assertThat import org.junit.Test internal class LatLngTest { @@ -28,33 +28,33 @@ internal class LatLngTest { fun `test that latLng can be destructured`() { val latLng = LatLng(2.0, 3.0) val (lat, lng) = latLng - assertEquals(2.0, lat, 1e-6) - assertEquals(3.0, lng, 1e-6) + assertThat(lat).isWithin(1e-6).of(2.0) + assertThat(lng).isWithin(1e-6).of(3.0) } @Test fun `single LatLng encoding`() { val line = listOf(LatLng(1.0, 2.0)) - assertEquals("_ibE_seK", line.latLngListEncode()) + assertThat(line.latLngListEncode()).isEqualTo("_ibE_seK") } @Test fun `single LatLng decoding`() { val lineEncoded = "_yfyF_ocsF" val line = lineEncoded.toLatLngList() - assertEquals(LatLng(41.0, 40.0), line.first()) + assertThat(line.first()).isEqualTo(LatLng(41.0, 40.0)) } @Test fun `closed polygon true`() { val latLngList = listOf(LatLng(1.0, 2.0), LatLng(3.0, 4.0), LatLng(1.0, 2.0)) - assertTrue(latLngList.isClosedPolygon()) + assertThat(latLngList.isClosedPolygon()).isTrue() } @Test fun `closed polygon false`() { val latLngList = listOf(LatLng(1.0, 2.0), LatLng(3.0, 4.0)) - assertFalse(latLngList.isClosedPolygon()) + assertThat(latLngList.isClosedPolygon()).isFalse() } @Test @@ -62,37 +62,37 @@ internal class LatLngTest { val lineEncoded = "elfjD~a}uNOnFN~Em@fJv@tEMhGDjDe@hG^nF??@lA?n@IvAC`Ay@A{@DwCA{CF_EC{CEi@PBTFDJBJ?V?n@?D@?A@?@?F?F?LAf@?n@@`@@T@~@FpA?fA?p@?r@?vAH`@OR@^ETFJCLD?JA^?J?P?fAC`B@d@?b@A\\@`@Ad@@\\?`@?f@?V?H?DD@DDBBDBD?D?B?B@B@@@B@B@B@D?D?JAF@H@FCLADBDBDCFAN?b@Af@@x@@" val line = lineEncoded.toLatLngList() val simplifiedLine = line.simplify(tolerance = 5.0) - assertEquals(20, simplifiedLine.size) - assertEquals(line.first(), simplifiedLine.first()) - assertEquals(line.last(), simplifiedLine.last()) + assertThat(simplifiedLine).hasSize(20) + assertThat(simplifiedLine.first()).isEqualTo(line.first()) + assertThat(simplifiedLine.last()).isEqualTo(line.last()) } @Test fun `heading is accurate`() { val up = LatLng(90.0, 0.0) val down = LatLng(-90.0, 0.0) - assertEquals(-180.0, up.sphericalHeading(down), 1e-6) + assertThat(up.sphericalHeading(down)).isWithin(1e-6).of(-180.0) } @Test fun `withOffset is accurate`() { val up = LatLng(90.0, 135.0) val down = up.withSphericalOffset(earthRadius, 180.0) - assertEquals(32.704220486917684, down.latitude, 1e-6) - assertEquals(-135.0, down.longitude, 1e-6) + assertThat(down.latitude).isWithin(1e-6).of(32.704220486917684) + assertThat(down.longitude).isWithin(1e-6).of(-135.0) } @Test fun `computeOffsetOrigin is accurate`() { val front = LatLng(0.0, 0.0) - assertEquals(front, front.computeSphericalOffsetOrigin(0.0, 0.0)) + assertThat(front.computeSphericalOffsetOrigin(0.0, 0.0)).isEqualTo(front) val result = LatLng(0.0, 45.0).computeSphericalOffsetOrigin( distance = Math.PI * earthRadius / 4.0, heading = 90.0 )!! - assertEquals(0.0, result.latitude, 1e-6) - assertEquals(0.0, result.longitude, 1e-6) + assertThat(result.latitude).isWithin(1e-6).of(0.0) + assertThat(result.longitude).isWithin(1e-6).of(0.0) } @Test @@ -101,32 +101,32 @@ internal class LatLngTest { val down = LatLng(-90.0, 0.0) val zeroFraction = up.withSphericalLinearInterpolation(down, 0.0) - assertEquals(90.0, zeroFraction.latitude, 1e-6) - assertEquals(0.0, zeroFraction.longitude, 1e-6) + assertThat(zeroFraction.latitude).isWithin(1e-6).of(90.0) + assertThat(zeroFraction.longitude).isWithin(1e-6).of(0.0) val halfFraction = up.withSphericalLinearInterpolation(down, 0.5) - assertEquals(0.0, halfFraction.latitude, 1e-6) - assertEquals(0.0, halfFraction.longitude, 1e-6) + assertThat(halfFraction.latitude).isWithin(1e-6).of(0.0) + assertThat(halfFraction.longitude).isWithin(1e-6).of(0.0) val oneFraction = up.withSphericalLinearInterpolation(down, 1.0) - assertEquals(-90.0, oneFraction.latitude, 1e-6) - assertEquals(0.0, oneFraction.longitude, 1e-6) + assertThat(oneFraction.latitude).isWithin(1e-6).of(-90.0) + assertThat(oneFraction.longitude).isWithin(1e-6).of(0.0) } @Test fun `compute spherical distance`() { val up = LatLng(90.0, 0.0) val down = LatLng(-90.0, 0.0) - assertEquals(Math.PI * earthRadius, up.sphericalDistance(down), 1e-6) + assertThat(up.sphericalDistance(down)).isWithin(1e-6).of(Math.PI * earthRadius) } @Test fun `validate spherical path length`() { - assertEquals(0.0, emptyList().sphericalPathLength(), 1e-6) + assertThat(emptyList().sphericalPathLength()).isWithin(1e-6).of(0.0) val latLngs = listOf(LatLng(0.0, 0.0), LatLng(0.1, 0.1)) val expectation = earthRadius * Math.sqrt(2.0) * Math.toRadians(0.1) - assertEquals(expectation, latLngs.sphericalPathLength(), 1e-1) + assertThat(latLngs.sphericalPathLength()).isWithin(1e-1).of(expectation) } @Test @@ -135,7 +135,7 @@ internal class LatLngTest { val down = LatLng(-90.0, 0.0) val right = LatLng(0.0, 90.0) val polygon = listOf(up, down, right, up) - assertEquals(1.2751647824926386E14, polygon.sphericalPolygonArea(), 1e-6) + assertThat(polygon.sphericalPolygonArea()).isWithin(1e-6).of(1.2751647824926386E14) println(polygon.sphericalPolygonSignedArea()) } @@ -146,46 +146,44 @@ internal class LatLngTest { val right = LatLng(0.0, 90.0) val polygon = listOf(up, down, right, up) val reversedPolygon = listOf(up, right, down, up) - assertEquals( - -polygon.sphericalPolygonSignedArea(), - reversedPolygon.sphericalPolygonSignedArea(), - 1e-6 - ) + assertThat(reversedPolygon.sphericalPolygonSignedArea()) + .isWithin(1e-6) + .of(-polygon.sphericalPolygonSignedArea()) } @Test fun `contains location evaluates to true`() { val latLngList = listOf(LatLng(0.0, 0.0), LatLng(0.0, 90.0), LatLng(-90.0, 45.0)) - assertTrue(latLngList.containsLocation(LatLng(30.0, 45.0), geodesic = true)) + assertThat(latLngList.containsLocation(LatLng(30.0, 45.0), geodesic = true)).isTrue() } @Test fun `contains location evaluates to false`() { val latLngList = listOf(LatLng(0.0, 0.0), LatLng(0.0, 90.0), LatLng(-90.0, 45.0)) - assertFalse(latLngList.containsLocation(LatLng(-30.0, 45.0), geodesic = true)) + assertThat(latLngList.containsLocation(LatLng(-30.0, 45.0), geodesic = true)).isFalse() } @Test fun `isOnEdge location evaluates to true`() { val latLngList = listOf(LatLng(0.0, 0.0), LatLng(0.0, 90.0), LatLng(-90.0, 45.0)) - assertTrue(latLngList.isOnEdge(LatLng(0.0, 45.0), geodesic = true)) + assertThat(latLngList.isOnEdge(LatLng(0.0, 45.0), geodesic = true)).isTrue() } @Test fun `isOnEdge location evaluates to false`() { val latLngList = listOf(LatLng(0.0, 0.0), LatLng(0.0, 90.0), LatLng(-90.0, 45.0)) - assertFalse(latLngList.isOnEdge(LatLng(0.0, -45.0), geodesic = true)) + assertThat(latLngList.isOnEdge(LatLng(0.0, -45.0), geodesic = true)).isFalse() } @Test fun `isLocationOnPath location evaluates to true`() { val latLngList = listOf(LatLng(0.0, 0.0), LatLng(0.0, 90.0), LatLng(0.0, 180.0)) - assertTrue(latLngList.isLocationOnPath(LatLng(0.0, 45.0), geodesic = true)) + assertThat(latLngList.isLocationOnPath(LatLng(0.0, 45.0), geodesic = true)).isTrue() } @Test fun `isLocationOnPath location evaluates to false`() { val latLngList = listOf(LatLng(0.0, 0.0), LatLng(0.0, 90.0), LatLng(0.0, 180.0)) - assertFalse(latLngList.isLocationOnPath(LatLng(0.0, -45.0), geodesic = true)) + assertThat(latLngList.isLocationOnPath(LatLng(0.0, -45.0), geodesic = true)).isFalse() } } \ No newline at end of file diff --git a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/PolygonTest.kt b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/PolygonTest.kt index eff0a221..d41c89a4 100644 --- a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/PolygonTest.kt +++ b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/PolygonTest.kt @@ -19,38 +19,37 @@ package com.google.maps.android.ktx.utils import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.Polygon +import com.google.common.truth.Truth.assertThat import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue import org.junit.Test internal class PolygonTest { @Test fun testContainsTrue() { val polygon = mockPolygon(listOf(LatLng(1.0, 2.2), LatLng(0.0, 1.0))) - assertTrue(polygon.contains(LatLng(1.0, 2.2))) + assertThat(polygon.contains(LatLng(1.0, 2.2))).isTrue() } @Test fun testContainsFalse() { val polygon = mockPolygon(listOf(LatLng(1.0, 2.2), LatLng(0.0, 1.0))) - assertFalse(polygon.contains(LatLng(1.01, 2.2))) + assertThat(polygon.contains(LatLng(1.01, 2.2))).isFalse() } @Test fun testIsOnEdgeTrue() { val polygon = mockPolygon(listOf(LatLng(1.0, 2.2), LatLng(0.0, 1.0))) - assertTrue(polygon.isOnEdge(LatLng(1.0, 2.2))) + assertThat(polygon.isOnEdge(LatLng(1.0, 2.2))).isTrue() // Tolerance - assertTrue(polygon.isOnEdge(LatLng(1.0000005, 2.2))) + assertThat(polygon.isOnEdge(LatLng(1.0000005, 2.2))).isTrue() } @Test fun testIsOnEdgeFalse() { val polygon = mockPolygon(listOf(LatLng(1.0, 2.2), LatLng(0.0, 1.0))) - assertFalse(polygon.isOnEdge(LatLng(3.0, 2.2))) + assertThat(polygon.isOnEdge(LatLng(3.0, 2.2))).isFalse() } private fun mockPolygon(p: List, geodesic: Boolean = true) = mock { diff --git a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/PolylineTest.kt b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/PolylineTest.kt index 90a88c9d..c044f836 100644 --- a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/PolylineTest.kt +++ b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/PolylineTest.kt @@ -19,11 +19,9 @@ package com.google.maps.android.ktx.utils import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.Polyline -import com.google.maps.android.ktx.utils.contains -import com.google.maps.android.ktx.utils.sphericalPathLength +import com.google.common.truth.Truth.assertThat import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock -import org.junit.Assert.* import org.junit.Test internal class PolylineTest { @@ -32,27 +30,27 @@ internal class PolylineTest { @Test fun `test that contains returns true`() { val line = mockPolyline(listOf(LatLng(1.0, 0.0), LatLng(3.0, 0.0))) - assertTrue(line.contains(LatLng(2.0, 0.0))) + assertThat(line.contains(LatLng(2.0, 0.0))).isTrue() } @Test fun `test that contains returns true with tolerance`() { val line = mockPolyline(listOf(LatLng(1.0, 0.0), LatLng(3.0, 0.0))) - assertTrue(line.contains(LatLng(1.0, 0.00000001))) + assertThat(line.contains(LatLng(1.0, 0.00000001))).isTrue() } @Test fun `test that contains returns false`() { val line = mockPolyline(listOf(LatLng(1.0, 0.0), LatLng(3.0, 0.0))) - assertFalse(line.contains(LatLng(4.0, 0.0))) + assertThat(line.contains(LatLng(4.0, 0.0))).isFalse() } @Test fun `validate spherical path length`() { - assertEquals(0.0, mockPolyline(emptyList()).sphericalPathLength, 1e-6) + assertThat(mockPolyline(emptyList()).sphericalPathLength).isWithin(1e-6).of(0.0) val polyline = mockPolyline(listOf(LatLng(0.0, 0.0), LatLng(0.1, 0.1))) val expectation = earthRadius * Math.sqrt(2.0) * Math.toRadians(0.1) - assertEquals(expectation, polyline.sphericalPathLength, 1e-1) + assertThat(polyline.sphericalPathLength).isWithin(1e-1).of(expectation) } private fun mockPolyline(p: List, geodesic: Boolean = true) = mock { diff --git a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/geometry/PointTest.kt b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/geometry/PointTest.kt index f04bddf9..f2fcd9ee 100644 --- a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/geometry/PointTest.kt +++ b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/geometry/PointTest.kt @@ -18,7 +18,7 @@ package com.google.maps.android.ktx.utils.geometry import com.google.maps.android.geometry.Point -import org.junit.Assert.assertEquals +import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test @@ -34,12 +34,12 @@ internal class PointTest { @Test fun `destructure x`() { val (x, _) = point - assertEquals(1.0, x, 1e-6) + assertThat(x).isWithin(1e-6).of(1.0) } @Test fun `destructure y`() { val (_, y) = point - assertEquals(2.0, y, 1e-6) + assertThat(y).isWithin(1e-6).of(2.0) } } \ No newline at end of file diff --git a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/heatmap/HeatmapTest.kt b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/heatmap/HeatmapTest.kt index 94588e04..efb54c79 100644 --- a/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/heatmap/HeatmapTest.kt +++ b/maps-utils-ktx/src/test/java/com/google/maps/android/ktx/utils/heatmap/HeatmapTest.kt @@ -18,9 +18,9 @@ package com.google.maps.android.ktx.utils.heatmap import com.google.android.gms.maps.model.LatLng +import com.google.common.truth.Truth.assertThat import com.google.maps.android.heatmaps.WeightedLatLng import com.google.maps.android.ktx.utils.heatmaps.toWeightedLatLng -import org.junit.Assert.* import org.junit.Test internal class HeatmapTest { @@ -36,8 +36,8 @@ internal class HeatmapTest { } private fun weightedLatLngEquals(lhs: WeightedLatLng, rhs: WeightedLatLng) { - assertEquals(lhs.point.x, rhs.point.x, 1e-6) - assertEquals(lhs.point.y, rhs.point.y, 1e-6) - assertEquals(lhs.intensity, rhs.intensity, 1e-6) + assertThat(lhs.point.x).isWithin(1e-6).of(rhs.point.x) + assertThat(lhs.point.y).isWithin(1e-6).of(rhs.point.y) + assertThat(lhs.intensity).isWithin(1e-6).of(rhs.intensity) } } \ No newline at end of file