From 9c715ce07524166f05ed17f4d7cda24686f8ba7b Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Sun, 12 Nov 2017 15:02:55 +0100 Subject: [PATCH] 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. --- .../kotlin/de/rpr/mycity/domain/city/JpaCityServiceTest.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/domain/src/test/kotlin/de/rpr/mycity/domain/city/JpaCityServiceTest.kt b/domain/src/test/kotlin/de/rpr/mycity/domain/city/JpaCityServiceTest.kt index 20f5904..461e907 100644 --- a/domain/src/test/kotlin/de/rpr/mycity/domain/city/JpaCityServiceTest.kt +++ b/domain/src/test/kotlin/de/rpr/mycity/domain/city/JpaCityServiceTest.kt @@ -94,6 +94,8 @@ internal class JpaCityServiceTest { fun `'updateCity' should update existing values`() { 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))) softly.assertThat(result).isNotNull @@ -102,7 +104,6 @@ internal class JpaCityServiceTest { softly.assertThat(result?.description).isEqualTo("new description") 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?.createdAt).isEqualTo(existingCity.createdAt) } @@ -115,6 +116,8 @@ internal class JpaCityServiceTest { location = Coordinate(1.0, -1.0), updatedAt = LocalDateTime.now().minusYears(1))).toDto() + Thread.sleep(1) + val result = service.updateCity(existingCity.id, UpdateCityDto(null, null, null)) softly.assertThat(result).isNotNull @@ -125,4 +128,4 @@ internal class JpaCityServiceTest { softly.assertThat(result?.updatedAt).isAfter(existingCity.updatedAt) softly.assertThat(result?.createdAt).isEqualTo(existingCity.createdAt) } -} \ No newline at end of file +}