From a47ef1ce8f395ab90cdb4cf970eb07bb22ef8339 Mon Sep 17 00:00:00 2001 From: IsaacAndra Date: Wed, 28 Aug 2024 18:35:58 -0300 Subject: [PATCH] :bug: fix: Corrigindo tolerancia de comparacao --- .../com/isaacandrade/blog/unittests/PostServiceTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/blog/src/test/java/com/isaacandrade/blog/unittests/PostServiceTest.java b/blog/src/test/java/com/isaacandrade/blog/unittests/PostServiceTest.java index 9db1388..40d6f1f 100644 --- a/blog/src/test/java/com/isaacandrade/blog/unittests/PostServiceTest.java +++ b/blog/src/test/java/com/isaacandrade/blog/unittests/PostServiceTest.java @@ -86,7 +86,7 @@ void findAllActivesPostsWithSuccess(){ assertEquals(1, result.size()); //Definindo uma tolerância para comparação dos segundos - Duration tolerance = Duration.ofSeconds(1); + Duration tolerance = Duration.ofMillis(1); //Aqui estou truncando os segundos do createdAt para que passem no test :p LocalDateTime expectedDate = postDTO.createdAt().truncatedTo(ChronoUnit.SECONDS); LocalDateTime actualDate = result.get(0).createdAt().truncatedTo(ChronoUnit.SECONDS); @@ -94,7 +94,10 @@ void findAllActivesPostsWithSuccess(){ assertTrue(Duration.between(expectedDate, actualDate).abs().compareTo(tolerance) <= 0, "Expected date: " + expectedDate + ", but was: " + actualDate); - assertEquals(postDTO, result.get(0)); + assertEquals(postDTO.id(), result.get(0).id()); + assertEquals(postDTO.title(), result.get(0).title()); + assertEquals(postDTO.content(), result.get(0).content()); + assertEquals(postDTO.isActive(), result.get(0).isActive()); verify(postRepository).findByIsActiveTrue(); verifyNoMoreInteractions(postRepository);