Skip to content

Commit

Permalink
fix: Corrigindo testes devido alteracoes
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacAndra committed Sep 29, 2024
1 parent ccee7b4 commit f9045f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void deletePostWithSuccess(){

postService.deletePost(createdPost.id());

PostDTO postDeleted = postService.findById(createdPost.id());
PostDTO postDeleted = postService.findByTitle(createdPost.title());

assertFalse(postDeleted.isActive(), "Deve estar com isActive setado como Falso!");
assertNotNull(createdPost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.mockito.Mockito.any;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -163,35 +163,35 @@ void findPostsWithAuthorIdWhenNoActivePosts(){
}


//----------TestsFindPostsById------------------------------------------------
//----------TestsFindPostsByTitle------------------------------------------------
@Test
void findPostsByIdWithSuccess(){
when(postRepository.findById(post.getId())).thenReturn(Optional.of(post));
void findPostsByTitleWithSuccess(){
when(postRepository.findByTitle(post.getTitle())).thenReturn(post);

PostDTO result = postService.findById(post.getId());
PostDTO result = postService.findByTitle(post.getTitle());

assertNotNull(result);
assertEquals(post.getTitle(), result.title());
assertEquals(post.getContent(), result.content());
assertEquals(post.getCreatedAt(), result.createdAt());
assertEquals(post.getIsActive(), result.isActive());

verify(postRepository).findById(post.getId());
verify(postRepository).findByTitle(post.getTitle());
verifyNoMoreInteractions(postRepository);
}

@Test
void findPostsByIdWhenPostWasNoFoundShouldException(){
when(postRepository.findById(post.getId())).thenReturn(Optional.empty());
when(postRepository.findByTitle(post.getTitle())).thenThrow(new PostNotFoundException());

PostNotFoundException exception = assertThrows(PostNotFoundException.class, () -> {
postService.findById(post.getId());
postService.findByTitle(post.getTitle());
});

MatcherAssert.assertThat(exception, notNullValue());
MatcherAssert.assertThat(exception.getMessage(), is("Post With Id " + post.getId() + " Was Not Found"));
MatcherAssert.assertThat(exception.getMessage(), is("Post Was Not Found"));

verify(postRepository).findById(post.getId());
verify(postRepository).findByTitle(post.getTitle());
verifyNoMoreInteractions(postRepository);
}

Expand Down

0 comments on commit f9045f0

Please sign in to comment.