From 013f43ca34e7b6f20eaceb13459ac476abf8c63f Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Thu, 13 Apr 2023 13:12:26 -0500 Subject: [PATCH] Fix tests --- .../java/org/tasks/data/LocationDaoTest.kt | 76 +++++++++---------- .../java/org/tasks/makers/GeofenceMaker.kt | 27 ------- .../test/java/org/tasks/makers/PlaceMaker.kt | 26 ------- 3 files changed, 35 insertions(+), 94 deletions(-) delete mode 100644 app/src/test/java/org/tasks/makers/GeofenceMaker.kt delete mode 100644 app/src/test/java/org/tasks/makers/PlaceMaker.kt diff --git a/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt b/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt index d5aca02cb..f37553741 100644 --- a/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt +++ b/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt @@ -15,14 +15,6 @@ import org.tasks.data.Alarm.Companion.TYPE_SNOOZE import org.tasks.date.DateTimeUtils.newDateTime import org.tasks.injection.InjectingTestCase import org.tasks.injection.ProductionModule -import org.tasks.makers.GeofenceMaker.ARRIVAL -import org.tasks.makers.GeofenceMaker.DEPARTURE -import org.tasks.makers.GeofenceMaker.PLACE -import org.tasks.makers.GeofenceMaker.TASK -import org.tasks.makers.GeofenceMaker.newGeofence -import org.tasks.makers.PlaceMaker.LATITUDE -import org.tasks.makers.PlaceMaker.LONGITUDE -import org.tasks.makers.PlaceMaker.newPlace import org.tasks.makers.TaskMaker.COMPLETION_TIME import org.tasks.makers.TaskMaker.DELETION_TIME import org.tasks.makers.TaskMaker.DUE_TIME @@ -40,7 +32,7 @@ class LocationDaoTest : InjectingTestCase() { @Test fun getExistingPlace() = runBlocking { - locationDao.insert(newPlace(with(LATITUDE, 48.067222), with(LONGITUDE, 12.863611))) + locationDao.insert(Place(latitude = 48.067222, longitude = 12.863611)) val place = locationDao.findPlace(48.067222.toLikeString(), 12.863611.toLikeString()) assertEquals(48.067222, place?.latitude) assertEquals(12.863611, place?.longitude) @@ -48,7 +40,7 @@ class LocationDaoTest : InjectingTestCase() { @Test fun getPlaceWithLessPrecision() = runBlocking { - locationDao.insert(newPlace(with(LATITUDE, 50.7547), with(LONGITUDE, -2.2279))) + locationDao.insert(Place(latitude = 50.7547, longitude = -2.2279)) val place = locationDao.findPlace(50.754712.toLikeString(), (-2.227945).toLikeString()) assertEquals(50.7547, place?.latitude) assertEquals(-2.2279, place?.longitude) @@ -56,7 +48,7 @@ class LocationDaoTest : InjectingTestCase() { @Test fun getPlaceWithMorePrecision() = runBlocking { - locationDao.insert(newPlace(with(LATITUDE, 36.246944), with(LONGITUDE, -116.816944))) + locationDao.insert(Place(latitude = 36.246944, longitude = -116.816944)) locationDao.getPlaces().forEach { println(it) } val place = locationDao.findPlace(36.2469.toLikeString(), (-116.8169).toLikeString()) assertEquals(36.246944, place?.latitude) @@ -65,20 +57,20 @@ class LocationDaoTest : InjectingTestCase() { @Test fun noActiveGeofences() = runBlocking { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask(with(ID, 1))) - locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid))) + locationDao.insert(Geofence(task = 1, place = place.uid)) assertNull(locationDao.getGeofencesByPlace(place.uid!!)) } @Test fun activeArrivalGeofence() = runBlocking { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask(with(ID, 1))) - locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true))) + locationDao.insert(Geofence(task = 1, place = place.uid, isArrival = true)) val geofence = locationDao.getGeofencesByPlace(place.uid!!) @@ -88,10 +80,10 @@ class LocationDaoTest : InjectingTestCase() { @Test fun activeDepartureGeofence() = runBlocking { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask(with(ID, 1))) - locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true))) + locationDao.insert(Geofence(task = 1, place = place.uid, isDeparture = true)) val geofence = locationDao.getGeofencesByPlace(place.uid!!) @@ -101,20 +93,20 @@ class LocationDaoTest : InjectingTestCase() { @Test fun geofenceInactiveForCompletedTask() = runBlocking { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask(with(ID, 1), with(COMPLETION_TIME, newDateTime()))) - locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true))) + locationDao.insert(Geofence(task = 1, place = place.uid, isArrival = true)) assertNull(locationDao.getGeofencesByPlace(place.uid!!)) } @Test fun geofenceInactiveForDeletedTask() = runBlocking { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask(with(ID, 1), with(DELETION_TIME, newDateTime()))) - locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true))) + locationDao.insert(Geofence(task = 1, place = place.uid, isArrival = true)) assertNull(locationDao.getGeofencesByPlace(place.uid!!)) } @@ -122,11 +114,11 @@ class LocationDaoTest : InjectingTestCase() { @Test fun ignoreArrivalForSnoozedTask() = runBlocking { freezeAt(now()).thawAfter { - val place = newPlace() + val place = Place() locationDao.insert(place) val task = taskDao.createNew(newTask()) alarmDao.insert(Alarm(task, newDateTime().plusMinutes(15).millis, TYPE_SNOOZE)) - locationDao.insert(newGeofence(with(TASK, task), with(PLACE, place.uid), with(ARRIVAL, true))) + locationDao.insert(Geofence(task = task, place = place.uid, isArrival = true)) assertTrue(locationDao.getArrivalGeofences(place.uid!!, now()).isEmpty()) } @@ -135,11 +127,11 @@ class LocationDaoTest : InjectingTestCase() { @Test fun ignoreDepartureForSnoozedTask() = runBlocking { freezeAt(now()).thawAfter { - val place = newPlace() + val place = Place() locationDao.insert(place) val task = taskDao.createNew(newTask()) alarmDao.insert(Alarm(task, newDateTime().plusMinutes(15).millis, TYPE_SNOOZE)) - locationDao.insert(newGeofence(with(TASK, task), with(PLACE, place.uid), with(DEPARTURE, true))) + locationDao.insert(Geofence(task = task, place = place.uid, isDeparture = true)) assertTrue(locationDao.getDepartureGeofences(place.uid!!, now()).isEmpty()) } @@ -148,12 +140,12 @@ class LocationDaoTest : InjectingTestCase() { @Test fun getArrivalWithElapsedSnooze() = runBlocking { freezeAt(now()).thawAfter { - val place = newPlace() + val place = Place() locationDao.insert(place) val task = taskDao.createNew(newTask()) alarmDao.insert(Alarm(task, newDateTime().minusMinutes(15).millis, TYPE_SNOOZE)) - val geofence = newGeofence(with(TASK, task), with(PLACE, place.uid), with(ARRIVAL, true)) - geofence.id = locationDao.insert(geofence) + val geofence = Geofence(task = task, place = place.uid, isArrival = true) + .let { it.copy(id = locationDao.insert(it)) } assertEquals(listOf(geofence), locationDao.getArrivalGeofences(place.uid!!, now())) } @@ -162,12 +154,12 @@ class LocationDaoTest : InjectingTestCase() { @Test fun getDepartureWithElapsedSnooze() = runBlocking { freezeAt(now()).thawAfter { - val place = newPlace() + val place = Place() locationDao.insert(place) val task = taskDao.createNew(newTask()) alarmDao.insert(Alarm(task, newDateTime().minusMinutes(15).millis, TYPE_SNOOZE)) - val geofence = newGeofence(with(TASK, task), with(PLACE, place.uid), with(DEPARTURE, true)) - geofence.id = locationDao.insert(geofence) + val geofence = Geofence(task = task, place = place.uid, isDeparture = true) + .let { it.copy(id = locationDao.insert(it)) } assertEquals(listOf(geofence), locationDao.getDepartureGeofences(place.uid!!, now())) } @@ -176,13 +168,13 @@ class LocationDaoTest : InjectingTestCase() { @Test fun ignoreArrivalForHiddenTask() = runBlocking { freezeAt(now()).thawAfter { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask( with(ID, 1), with(DUE_TIME, newDateTime().plusMinutes(15)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))) - locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true))) + locationDao.insert(Geofence(task = 1, place = place.uid, isArrival = true)) assertTrue(locationDao.getArrivalGeofences(place.uid!!, now()).isEmpty()) } @@ -191,13 +183,13 @@ class LocationDaoTest : InjectingTestCase() { @Test fun ignoreDepartureForHiddenTask() = runBlocking { freezeAt(now()).thawAfter { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask( with(ID, 1), with(DUE_TIME, newDateTime().plusMinutes(15)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))) - locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true))) + locationDao.insert(Geofence(task = 1, place = place.uid, isDeparture = true)) assertTrue(locationDao.getDepartureGeofences(place.uid!!, now()).isEmpty()) } @@ -206,14 +198,16 @@ class LocationDaoTest : InjectingTestCase() { @Test fun getArrivalWithElapsedHideUntil() = runBlocking { freezeAt(now()).thawAfter { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask( with(ID, 1), with(DUE_TIME, newDateTime().minusMinutes(15)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))) - val geofence = newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true)) - geofence.id = locationDao.insert(geofence) + val geofence = Geofence(task = 1, place = place.uid, isArrival = true) + .let { + it.copy(id = locationDao.insert(it)) + } assertEquals(listOf(geofence), locationDao.getArrivalGeofences(place.uid!!, now())) } @@ -222,14 +216,14 @@ class LocationDaoTest : InjectingTestCase() { @Test fun getDepartureWithElapsedHideUntil() = runBlocking { freezeAt(now()).thawAfter { - val place = newPlace() + val place = Place() locationDao.insert(place) taskDao.createNew(newTask( with(ID, 1), with(DUE_TIME, newDateTime().minusMinutes(15)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))) - val geofence = newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true)) - geofence.id = locationDao.insert(geofence) + val geofence = Geofence(task = 1, place = place.uid, isDeparture = true) + .let { it.copy(id = locationDao.insert(it)) } assertEquals(listOf(geofence), locationDao.getDepartureGeofences(place.uid!!, now())) } diff --git a/app/src/test/java/org/tasks/makers/GeofenceMaker.kt b/app/src/test/java/org/tasks/makers/GeofenceMaker.kt deleted file mode 100644 index 900cd0d8c..000000000 --- a/app/src/test/java/org/tasks/makers/GeofenceMaker.kt +++ /dev/null @@ -1,27 +0,0 @@ -package org.tasks.makers - -import com.natpryce.makeiteasy.Instantiator -import com.natpryce.makeiteasy.Property -import com.natpryce.makeiteasy.PropertyLookup -import com.natpryce.makeiteasy.PropertyValue -import org.tasks.data.Geofence - -object GeofenceMaker { - val PLACE: Property = Property.newProperty() - val TASK: Property = Property.newProperty() - val ARRIVAL: Property = Property.newProperty() - val DEPARTURE: Property = Property.newProperty() - - private val instantiator = Instantiator { lookup: PropertyLookup -> - val geofence = Geofence() - geofence.place = lookup.valueOf(PLACE, "") - geofence.task = lookup.valueOf(TASK, 1) - geofence.isArrival = lookup.valueOf(ARRIVAL, false) - geofence.isDeparture = lookup.valueOf(DEPARTURE, false) - geofence - } - - fun newGeofence(vararg properties: PropertyValue): Geofence { - return Maker.make(instantiator, *properties) - } -} \ No newline at end of file diff --git a/app/src/test/java/org/tasks/makers/PlaceMaker.kt b/app/src/test/java/org/tasks/makers/PlaceMaker.kt deleted file mode 100644 index bdcb00537..000000000 --- a/app/src/test/java/org/tasks/makers/PlaceMaker.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.tasks.makers - -import com.natpryce.makeiteasy.Instantiator -import com.natpryce.makeiteasy.Property -import com.natpryce.makeiteasy.PropertyLookup -import com.natpryce.makeiteasy.PropertyValue -import com.todoroo.astrid.helper.UUIDHelper -import org.tasks.data.Place - -object PlaceMaker { - val LATITUDE: Property = Property.newProperty() - val LONGITUDE: Property = Property.newProperty() - val UUID: Property = Property.newProperty() - - private val instantiator = Instantiator { lookup: PropertyLookup -> - val place = Place() - place.uid = lookup.valueOf(UUID, UUIDHelper.newUUID()) - place.latitude = lookup.valueOf(LATITUDE, 0.0) - place.longitude = lookup.valueOf(LONGITUDE, 0.0) - place - } - - fun newPlace(vararg properties: PropertyValue): Place { - return Maker.make(instantiator, *properties) - } -} \ No newline at end of file