Skip to content

Commit

Permalink
Fix null values in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Prince committed Nov 7, 2023
1 parent 063e00f commit 262bf5c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ class LoiLocalDataStoreConverterTest {
mockLoiDocumentSnapshot(
"loi001",
LoiDocument(
/* jobId */ "job001",
/* customId */null,
/* location */ null,
/* geoJson */ null,
/* geometry */ null,
/* created */ AUDIT_INFO_1_NESTED_OBJECT,
/* lastModified */ AUDIT_INFO_2_NESTED_OBJECT
/* jobId */ "job001",
/* customId */ null,
/* location */ null,
/* geoJson */ null,
/* geometry */ null,
/* created */ AUDIT_INFO_1_NESTED_OBJECT,
/* lastModified */ AUDIT_INFO_2_NESTED_OBJECT
)
)
assertThat(toLocationOfInterest().isFailure).isTrue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class LocationOfInterestRepositoryTest : BaseHiltTest() {
// TODO(#1559): Remove once customId and caption are handled consistently.
val loi =
LOCATION_OF_INTEREST.copy(
customId = null,
customId = "",
// TODO(#1562): Remove once creation time is preserved in local db.
lastModified = LOCATION_OF_INTEREST.created
)
Expand Down Expand Up @@ -194,15 +194,15 @@ class LocationOfInterestRepositoryTest : BaseHiltTest() {
id = id,
geometry = Point(coordinate),
surveyId = TEST_SURVEY.id,
customId = null
customId = ""
)

private fun createPolygon(id: String, coordinates: List<Coordinates>) =
AREA_OF_INTEREST.copy(
id = id,
geometry = Polygon(LinearRing(coordinates)),
surveyId = TEST_SURVEY.id,
customId = null
customId = ""
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LocationOfInterestHelperTest : BaseHiltTest() {

@Test
fun testGetLabel_whenCaptionIsEmptyAndLoiIsPolygon() {
val loi = FakeData.AREA_OF_INTEREST.copy( "")
val loi = FakeData.AREA_OF_INTEREST.copy("")
assertLabel(loi, "Polygon")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ class LoiCardUtilTest {

@Test
fun testLoiNameWithPoint_whenCustomIdAndPropertiesAreNull() {
assertThat(getDisplayLoiName(context, TEST_LOI.copy(customId = null, properties = null))).isEqualTo("Unnamed point")
assertThat(getDisplayLoiName(context, TEST_LOI.copy(customId = "", properties = mapOf())))
.isEqualTo("Unnamed point")
}

@Test
fun testLoiNameWithPolygon_whenCustomIdAndPropertiesAreNull() {
assertThat(getDisplayLoiName(context, TEST_AREA.copy(customId = null, properties = null))).isEqualTo("Unnamed area")
assertThat(getDisplayLoiName(context, TEST_AREA.copy(customId = "", properties = mapOf())))
.isEqualTo("Unnamed area")
}

@Test
Expand All @@ -55,25 +57,42 @@ class LoiCardUtilTest {

@Test
fun testArea_whenCustomIdIsNotAvailable_usesPropertiesId() {
assertThat(getDisplayLoiName(context, TEST_AREA.copy(customId = null, properties = mapOf("id" to "property id"))))
assertThat(
getDisplayLoiName(
context,
TEST_AREA.copy(customId = "", properties = mapOf("id" to "property id"))
)
)
.isEqualTo("Area (property id)")
}

@Test
fun testLoiName_whenPropertiesNameIsAvailable() {
assertThat(getDisplayLoiName(context, TEST_LOI.copy(properties = mapOf("name" to "custom name"))))
assertThat(
getDisplayLoiName(context, TEST_LOI.copy(properties = mapOf("name" to "custom name")))
)
.isEqualTo("custom name")
}

@Test
fun testLoiName_whenCustomIdAndPropertiesNameIsAvailable() {
assertThat(getDisplayLoiName(context, TEST_LOI.copy(customId = "some value",properties = mapOf("name" to "custom name") )))
assertThat(
getDisplayLoiName(
context,
TEST_LOI.copy(customId = "some value", properties = mapOf("name" to "custom name"))
)
)
.isEqualTo("custom name (some value)")
}

@Test
fun testLoiName_whenPropertiesDoesNotContainName() {
assertThat(getDisplayLoiName(context, TEST_LOI.copy(customId = null, properties = mapOf("not" to "a name field"))))
assertThat(
getDisplayLoiName(
context,
TEST_LOI.copy(customId = "", properties = mapOf("not" to "a name field"))
)
)
.isEqualTo("Unnamed point")
}

Expand Down
2 changes: 1 addition & 1 deletion sharedTest/src/main/kotlin/com/sharedtest/FakeData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object FakeData {
"loi id",
SURVEY.id,
JOB,
customId = null,
customId = "",
created = AuditInfo(USER),
lastModified = AuditInfo(USER),
geometry = Point(Coordinates(0.0, 0.0)),
Expand Down

0 comments on commit 262bf5c

Please sign in to comment.