Last active
July 27, 2021 12:57
-
-
Save babjo/11a7642fbb1822c553f25918a061f216 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 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