Migrate TestNavigatorDestinationBuilderTest to Google Truth asserts
Migrating TestNavigatorDestinationBuilderTest to use Google Truth
asserts, rather than the previously used junit asserts.
Bug: 187184284
Test: Run test file
Change-Id: I6e98904d41f04a70c1f6da8042e80af54e82befc
diff --git a/testutils/testutils-navigation/build.gradle b/testutils/testutils-navigation/build.gradle
index 6e705df..a5d1779 100644
--- a/testutils/testutils-navigation/build.gradle
+++ b/testutils/testutils-navigation/build.gradle
@@ -32,4 +32,5 @@
androidTestImplementation(libs.testCore)
androidTestImplementation(libs.testRunner)
androidTestImplementation(libs.espressoCore)
+ androidTestImplementation(libs.truth)
}
diff --git a/testutils/testutils-navigation/src/androidTest/java/androidx/testutils/TestNavigatorDestinationBuilderTest.kt b/testutils/testutils-navigation/src/androidTest/java/androidx/testutils/TestNavigatorDestinationBuilderTest.kt
index 20383a3..d76d9e4 100644
--- a/testutils/testutils-navigation/src/androidTest/java/androidx/testutils/TestNavigatorDestinationBuilderTest.kt
+++ b/testutils/testutils-navigation/src/androidTest/java/androidx/testutils/TestNavigatorDestinationBuilderTest.kt
@@ -21,8 +21,7 @@
import androidx.navigation.navigation
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
-import org.junit.Assert.assertEquals
-import org.junit.Assert.assertTrue
+import com.google.common.truth.Truth.assertWithMessage
import org.junit.Test
import org.junit.runner.RunWith
@@ -37,10 +36,9 @@
val graph = provider.navigation(startDestination = DESTINATION_ID) {
test(DESTINATION_ID)
}
- assertTrue(
- "Destination should be added to the graph",
- DESTINATION_ID in graph
- )
+ assertWithMessage("Destination should be added to the graph")
+ .that(DESTINATION_ID in graph)
+ .isTrue()
}
@Test
@@ -48,10 +46,9 @@
val graph = provider.navigation(startDestination = DESTINATION_ROUTE) {
test(DESTINATION_ROUTE)
}
- assertTrue(
- "Destination should be added to the graph",
- DESTINATION_ROUTE in graph
- )
+ assertWithMessage("Destination should be added to the graph")
+ .that(DESTINATION_ROUTE in graph)
+ .isTrue()
}
@Suppress("DEPRECATION")
@@ -62,14 +59,12 @@
label = LABEL
}
}
- assertTrue(
- "Destination should be added to the graph",
- DESTINATION_ID in graph
- )
- assertEquals(
- "Destination should have label set",
- LABEL, graph[DESTINATION_ID].label
- )
+ assertWithMessage("Destination should be added to the graph")
+ .that(DESTINATION_ID in graph)
+ .isTrue()
+ assertWithMessage("Destination should have label set")
+ .that(graph[DESTINATION_ID].label)
+ .isEqualTo(LABEL)
}
@Test
@@ -79,14 +74,12 @@
label = LABEL
}
}
- assertTrue(
- "Destination should be added to the graph",
- DESTINATION_ROUTE in graph
- )
- assertEquals(
- "Destination should have label set",
- LABEL, graph[DESTINATION_ROUTE].label
- )
+ assertWithMessage("Destination should be added to the graph")
+ .that(DESTINATION_ROUTE in graph)
+ .isTrue()
+ assertWithMessage("Destination should have label set")
+ .that(graph[DESTINATION_ROUTE].label)
+ .isEqualTo(LABEL)
}
}