Skip to content

Commit

Permalink
🐛 fix: Corrigindo tolerancia de comparacao
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacAndra committed Aug 28, 2024
1 parent 212f769 commit a47ef1c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ 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);

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);
Expand Down

0 comments on commit a47ef1c

Please sign in to comment.