Open
Conversation
Open
9 tasks
Contributor
|
User는 빼고 커밋해야할듯 |
Contributor
|
wnso-kim
reviewed
Apr 8, 2024
Comment on lines
43
to
62
| @Test | ||
| void getAllPosts() throws Exception { | ||
|
|
||
| //given | ||
| when(postService.getAllPosts()).thenReturn(Arrays.asList( | ||
| new Post(1L, "First post", LocalDateTime.now(), LocalDateTime.now(), 0L, 0L, 0L, new User()), | ||
| new Post(2L, "Second post", LocalDateTime.now(), LocalDateTime.now(), 0L, 0L, 0L, new User()) | ||
| )); | ||
|
|
||
| MockMvc mockMvc = MockMvcBuilders.standaloneSetup(postController).build(); | ||
|
|
||
| //when | ||
| mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/posts")) | ||
| //then | ||
| .andExpect(status().isOk()) | ||
| .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(Arrays.asList( | ||
| new Post(1L, "First post", LocalDateTime.now(), LocalDateTime.now(), 0L, 0L, 0L, new User()), | ||
| new Post(2L, "Second post", LocalDateTime.now(), LocalDateTime.now(), 0L, 0L, 0L, new User()) | ||
| )))); | ||
| } |
There was a problem hiding this comment.
Test를 빠르게 확인하기 위해, 메소드를 한글명으로 하거나 @DisplayName을 사용해 주세요.
그리고, service에서는 필요한 테스트가 없었나요?
Comment on lines
36
to
43
| public Post updatePost(Long id, Post postDetails) { | ||
| Post post = postRepository.findById(id) | ||
| .orElseThrow(() -> new RuntimeException()); | ||
|
|
||
| post.setContents(postDetails.getContents()); | ||
|
|
||
| return postRepository.save(post); | ||
| } |
There was a problem hiding this comment.
팀원의 업데이트 방식과 상이합니다. 경호씨는 dirty check 사용하셨어요!
wnso-kim
reviewed
Apr 8, 2024
| @Getter @Setter | ||
| public class Post { | ||
| @Id | ||
| @GeneratedValue |
There was a problem hiding this comment.
ID 생성 전략이 기본 값으로 돼 있어서 MySQL을 사용하신다면 sequence 전략일 겁니다.
경호씨는 다른 전략 사용하셨던데, 테이블마다 전략이 다른게 아니라면 맞춰주세요!
Contributor
Author
There was a problem hiding this comment.
시정하겠습니다 !! 대가리 박겠습니다!!
kkho9654
reviewed
Apr 15, 2024
Comment on lines
51
to
56
| @DisplayName("게시글 전부 조회 예외 테스트") | ||
| @Test | ||
| void 게시글전부조회예외테스트() { | ||
| when(postRepository.findAll()).thenThrow(new RuntimeException()); | ||
| assertThrows(RuntimeException.class, () -> postService.getAllPosts()); | ||
| } |
Contributor
There was a problem hiding this comment.
그냥 Runtime 예외보다는 구체적으로 어떤 예외인지 정의해서 예외처리하는 것이 좋을 것 같습니다.
Comment on lines
110
to
121
| @Test | ||
| void 게시글수정테스트() { | ||
| //given | ||
| when(postRepository.findById(1L)).thenReturn(Optional.of(post)); | ||
| when(postRepository.save(any(Post.class))).thenReturn(post); | ||
| Post updatedPost = new Post(); | ||
| //when | ||
| updatedPost.setContents("Updated Contents"); | ||
| Post result = postService.updatePost(1L, updatedPost); | ||
| //then | ||
| assertThat(result.getContents()).isEqualTo("Updated Contents"); | ||
| } |
Comment on lines
9
to
27
| @Entity | ||
| @Getter @Setter | ||
| public class PostReply { | ||
| @Id | ||
| @GeneratedValue | ||
| private Long id; | ||
|
|
||
| private String contents; | ||
|
|
||
| private LocalDateTime createdAt; | ||
|
|
||
| private LocalDateTime updatedAt; | ||
|
|
||
| private Long likes; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "post_id") | ||
| private Post post; | ||
| } |
Contributor
There was a problem hiding this comment.
dto가 있는데 왜 entity로 postReply가 있는건가요?
Comment on lines
34
to
40
| public Post(long l, String firstPost, LocalDateTime now, LocalDateTime now1, long l1, long l2, long l3, User user) { | ||
| } | ||
|
|
||
|
|
||
| public Post() { | ||
|
|
||
| } |
Contributor
|
좋아요 |
wintiger98
approved these changes
Apr 22, 2024
cf14851 to
c416a97
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
name: Post crud task
about: Post crud task
작업 내용:
게시판 CRUD 구현
이번에 공들였던 부분:
질문:
제출 전 필수 확인 사항: