함수형 코드로 리팩터링을 하는 과정에서 이런 패턴의 리팩터링을 자주 보게 된다. 동작의 범
위를 줄임에 따라 테스트 코드에서 테스트 상태를 준비하는 과정이 사라지고 여러 가지 파라미
터 값을 시험해 보는 코드로 바뀌기 때문에, 테스트가 더 단순해진다.
4
이에 대해서는
17
장에
서 다시 살펴본다.
7.6.3
마지막 단계
이제 거의 다 끝났다. 물론 리팩터링이 완전히 끝나는 일은 없다.
테스트에 초점을 맞춘 이 모든 변경 사항을 체크인하려고 보니, 아직
CurrentTripsHandler
의 리팩터링을 끝내지 않았다는 사실을 발견하게 된다.
예제
7.18
[
actions
.
8
:
src
/
main
/
java
/
travelator
/
handlers
/
CurrentTripsHandler
.
java
]
public Response handle(Request request) {
try {
var customerId = request.getQueryParam(“customerId”).stream()
.findFirst();
if (customerId.isEmpty())
return new Response(HTTP_BAD_REQUEST);
var currentTrip ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.