Skip to content

Instantly share code, notes, and snippets.

@babjo
Last active July 27, 2021 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save babjo/11a7642fbb1822c553f25918a061f216 to your computer and use it in GitHub Desktop.
Save babjo/11a7642fbb1822c553f25918a061f216 to your computer and use it in GitHub Desktop.
public class BlogService {
public BlogService(AuthClient authClient, BlogRepository repository) {
this.authClient = authClient;
this.repository = repository;
}
public AddPostResponse addPost(AddPostRequest request) {
// verifyToken 메소드 파라미터 추가
// 리턴 값이 User 객체로 변경
User user = authClient.verifyToken(request.getToken(), request.getClientIp());
Post post = request.getPost();
long postId = repository.save(user.getId(), post);
return new AddPostResponse(user.getId(), post);
}
}
public class BlogServiceTest {
...
@Test
public void addPost() {
// given
given(authClient.verifyToken(anyString())).willReturn(1L); // 깨짐
...
// then
verify(authClient).should().verifyToken(anyString()); // 깨짐
...
}
@Test
public void addPost_thrownByAuthClient() {
// given
given(repository.save(any())).willThrow(new RuntimeException()); // 깨짐
...
// then
verify(authClient).should().verifyToken(any()); // 깨짐
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment