From 45bd5c983ca01396529bbcb4d14a4357d1182d1d Mon Sep 17 00:00:00 2001 From: ReO Date: Tue, 15 Aug 2023 23:15:34 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20=EC=97=AC=ED=96=89=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#289)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/domain/trip/Route.java | 6 ++++++ .../main/java/dev/tripdraw/domain/trip/Trip.java | 4 +--- .../tripdraw/application/TripServiceTest.java | 9 +++------ .../java/dev/tripdraw/domain/trip/RouteTest.java | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/Route.java b/backend/src/main/java/dev/tripdraw/domain/trip/Route.java index 59bdb48c4..03efb6512 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/Route.java +++ b/backend/src/main/java/dev/tripdraw/domain/trip/Route.java @@ -47,4 +47,10 @@ public void deletePointById(Long pointId) { pointToDelete.delete(); } + + public List points() { + return points.stream() + .filter(point -> !point.isDeleted()) + .toList(); + } } diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/Trip.java b/backend/src/main/java/dev/tripdraw/domain/trip/Trip.java index a426cbbd2..a72e18023 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/Trip.java +++ b/backend/src/main/java/dev/tripdraw/domain/trip/Trip.java @@ -152,9 +152,7 @@ public void deletePointById(Long pointId) { } public List points() { - return route.points().stream() - .filter(point -> !point.isDeleted()) - .toList(); + return route.points(); } public String nameValue() { diff --git a/backend/src/test/java/dev/tripdraw/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/application/TripServiceTest.java index 2a656cfc8..56eb8db03 100644 --- a/backend/src/test/java/dev/tripdraw/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/application/TripServiceTest.java @@ -117,13 +117,10 @@ void setUp() { tripService.deletePoint(loginUser, response.pointId(), trip.id()); // then - Point deletedPoint = trip.route().points() + assertThat(trip.route().points() .stream() - .filter(point -> Objects.equals(point.id(), response.pointId())) - .findFirst() - .get(); - - assertThat(deletedPoint.isDeleted()).isTrue(); + .anyMatch(point -> Objects.equals(point.id(), response.pointId()))) + .isFalse(); } @Test diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/RouteTest.java b/backend/src/test/java/dev/tripdraw/domain/trip/RouteTest.java index ba252bc65..9f4277037 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/RouteTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/trip/RouteTest.java @@ -102,5 +102,21 @@ class RouteTest { .isInstanceOf(TripException.class) .hasMessage(POINT_NOT_FOUND.message()); } + + @Test + void 삭제된_위치정보는_반환하지_않는다() { + // given + Route route = new Route(); + Point point1 = new Point(1L, 1.1, 2.1, false, LocalDateTime.now()); + Point point2 = new Point(2L, 3.1, 4.1, false, LocalDateTime.now()); + route.add(point1); + route.add(point2); + + // when + route.deletePointById(1L); + + // then + assertThat(route.points()).containsExactly(point2); + } }