Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
test(#32): Add UT
Browse files Browse the repository at this point in the history
- Add test case for getting posts by status
  • Loading branch information
lealceldeiro committed Jan 24, 2022
1 parent aa28c6e commit c68c333
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rest/src/test/java/org/wcdevs/blog/core/rest/TestsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.util.ResourceUtils;
import org.wcdevs.blog.core.persistence.comment.CommentDto;
import org.wcdevs.blog.core.persistence.post.PostDto;
import org.wcdevs.blog.core.persistence.post.PostStatus;

public final class TestsUtil {
public static final ResponseFieldsSnippet ERROR_RESPONSE_FIELDS
Expand Down Expand Up @@ -185,4 +186,9 @@ public static <T> Page<T> pageOf(T element, T... elements) {
public static Pageable pageable() {
return Pageable.ofSize(10);
}

public static PostStatus aRandomPostStatus() {
var values = PostStatus.values();
return values[RANDOM.nextInt(values.length)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ void getPosts() throws Exception {
.andDo(document("get_posts", fields));
}

@Test
void getPostsWithStatus() throws Exception {
var status = TestsUtil.aRandomPostStatus();
when(postService.getPosts(eq(status), any(Pageable.class)))
.then(ignored -> TestsUtil.pageOf(TestsUtil.samplePostsLiteData()));

mockMvc.perform(get(BASE_URL + "/status/{postStatus}", status)).andExpect(status().isOk());
}

@Test
void createPost() throws Exception {
var postDto = TestsUtil.samplePostTitleBody();
Expand Down

0 comments on commit c68c333

Please sign in to comment.