Last active
July 27, 2021 14:04
-
-
Save babjo/277a2e671cf692707cf2f687d9a15ce9 to your computer and use it in GitHub Desktop.
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
public class BlogServiceTest { | |
@Test | |
public void addPost() { | |
// given | |
AuthClient authClient = ... | |
BlogRepository blogRepository = ... | |
BlogService service = new BlogService(authClient, blogRepository); // 생성자로 협력 객체 주입 | |
AddPostRequest request = ... | |
// when | |
service.addPost(request); | |
// then | |
... | |
} | |
} | |
public class BlogService { | |
public BlogService(AuthClient authClient, BlogRepository blogRepository) { | |
this.authClient = authClient; | |
this.blogRepository = blogRepository; | |
} | |
public AddPostResponse addPost(AddPostRequest request) { | |
long userId = authClient.verifyToken(request.getToken()); | |
Post post = request.getPost(); | |
long postId = blogRepository.save(userId, post); | |
return new AddPostResponse(userId, post); | |
} | |
public GetPostResponse getPosts(GetPostRequest request) { | |
long userId = authClient.verifyToken(request.getToken()); | |
return new GetPostResponse(blogRepository.findByUserId(userId)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment