Skip to content

Commit 809b104

Browse files
committed
Added tests for #getByIdNot
1 parent f32b51a commit 809b104

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

collect_app/src/test/java/org/odk/collect/android/entities/EntitiesRepositoryTest.kt

+64
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,70 @@ abstract class EntitiesRepositoryTest {
515515
assertThat(queriedCanet, equalTo(otherFavouriteWines.first { it.id == "2" }))
516516
}
517517

518+
@Test
519+
fun `#getByIdNot returns entities with not matching id`() {
520+
val repository = buildSubject()
521+
522+
val leoville = Entity.New("1", "Léoville Barton 2008")
523+
val canet = Entity.New("2", "Pontet-Canet 2014")
524+
repository.save("wines", leoville, canet)
525+
526+
val wines = repository.getEntities("wines")
527+
528+
val queriedLeoville = repository.getByIdNot("wines", "1")
529+
assertThat(queriedLeoville, equalTo(wines.first { it.id == "2" }))
530+
531+
val queriedCanet = repository.getByIdNot("wines", "2")
532+
assertThat(queriedCanet, equalTo(wines.first { it.id == "1" }))
533+
}
534+
535+
@Test
536+
fun `#getByIdNot returns null when there are no matches`() {
537+
val repository = buildSubject()
538+
539+
val leoville = Entity.New("1", "Léoville Barton 2008")
540+
repository.save("wines", leoville)
541+
542+
assertThat(repository.getByIdNot("wines", "1"), equalTo(null))
543+
}
544+
545+
@Test
546+
fun `#getByIdNot returns null when there is a match in a different list`() {
547+
val repository = buildSubject()
548+
549+
val leoville = Entity.New("1", "Léoville Barton 2008")
550+
val ardbeg = Entity.New("2", "Ardbeg 10")
551+
repository.save("wines", leoville)
552+
repository.save("whisky", ardbeg)
553+
554+
assertThat(repository.getByIdNot("whisky", "2"), equalTo(null))
555+
}
556+
557+
@Test
558+
fun `#getByIdNot returns null where there are no entities in the list`() {
559+
val repository = buildSubject()
560+
assertThat(repository.getByIdNot("wines", "3"), equalTo(null))
561+
}
562+
563+
@Test
564+
fun `#getByIdNot supports list names with dots and dashes`() {
565+
val repository = buildSubject()
566+
567+
val leoville = Entity.New("1", "Léoville Barton 2008")
568+
val canet = Entity.New("2", "Pontet-Canet 2014")
569+
repository.save("favourite-wines", leoville)
570+
repository.save("other.favourite.wines", canet)
571+
572+
val favouriteWines = repository.getEntities("favourite-wines")
573+
val otherFavouriteWines = repository.getEntities("other.favourite.wines")
574+
575+
val queriedLeoville = repository.getByIdNot("favourite-wines", "2")
576+
assertThat(queriedLeoville, equalTo(favouriteWines.first { it.id == "1" }))
577+
578+
val queriedCanet = repository.getByIdNot("other.favourite.wines", "1")
579+
assertThat(queriedCanet, equalTo(otherFavouriteWines.first { it.id == "2" }))
580+
}
581+
518582
@Test
519583
fun `#getByLabel returns entities with matching label`() {
520584
val repository = buildSubject()

0 commit comments

Comments
 (0)