Fix test for updatedAt property
Both `save` and `updateCity` calls can happen at the same millisecond, therefore the `updatedAt` was not necessarily increased. The `Thread.sleep` method doesn't mention any guarantees of increasing the system time mentioned by `LocalDateTime` used in `CityEntity`, but the tests didn't fail again with this change, even when run repeatedly.
This commit is contained in:
parent
5cf200dd0f
commit
9c715ce075
1 changed files with 5 additions and 2 deletions
|
@ -94,6 +94,8 @@ internal class JpaCityServiceTest {
|
||||||
fun `'updateCity' should update existing values`() {
|
fun `'updateCity' should update existing values`() {
|
||||||
val existingCity = repository.save(CityEntity("city", "cityname", "description", Coordinate(1.0, -1.0))).toDto()
|
val existingCity = repository.save(CityEntity("city", "cityname", "description", Coordinate(1.0, -1.0))).toDto()
|
||||||
|
|
||||||
|
Thread.sleep(1)
|
||||||
|
|
||||||
val result = service.updateCity(existingCity.id, UpdateCityDto("new name", "new description", CoordinateDto(-1.0, -1.0)))
|
val result = service.updateCity(existingCity.id, UpdateCityDto("new name", "new description", CoordinateDto(-1.0, -1.0)))
|
||||||
|
|
||||||
softly.assertThat(result).isNotNull
|
softly.assertThat(result).isNotNull
|
||||||
|
@ -102,7 +104,6 @@ internal class JpaCityServiceTest {
|
||||||
softly.assertThat(result?.description).isEqualTo("new description")
|
softly.assertThat(result?.description).isEqualTo("new description")
|
||||||
softly.assertThat(result?.location).isEqualTo(CoordinateDto(-1.0, -1.0))
|
softly.assertThat(result?.location).isEqualTo(CoordinateDto(-1.0, -1.0))
|
||||||
softly.assertThat(result?.updatedAt).isAfter(existingCity.updatedAt)
|
softly.assertThat(result?.updatedAt).isAfter(existingCity.updatedAt)
|
||||||
softly.assertThat(result?.updatedAt).isAfter(existingCity.updatedAt)
|
|
||||||
softly.assertThat(result?.createdAt).isEqualTo(existingCity.createdAt)
|
softly.assertThat(result?.createdAt).isEqualTo(existingCity.createdAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +116,8 @@ internal class JpaCityServiceTest {
|
||||||
location = Coordinate(1.0, -1.0),
|
location = Coordinate(1.0, -1.0),
|
||||||
updatedAt = LocalDateTime.now().minusYears(1))).toDto()
|
updatedAt = LocalDateTime.now().minusYears(1))).toDto()
|
||||||
|
|
||||||
|
Thread.sleep(1)
|
||||||
|
|
||||||
val result = service.updateCity(existingCity.id, UpdateCityDto(null, null, null))
|
val result = service.updateCity(existingCity.id, UpdateCityDto(null, null, null))
|
||||||
|
|
||||||
softly.assertThat(result).isNotNull
|
softly.assertThat(result).isNotNull
|
||||||
|
|
Loading…
Reference in a new issue