From 2afd4197bdcc2225b90aa780a97dbc399edbeae2 Mon Sep 17 00:00:00 2001 From: heondong9265 Date: Fri, 31 May 2024 20:35:34 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A7=80=ED=95=98=EC=B2=A0=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20#03=20feat=20:=20=EC=A7=80=ED=95=98=EC=B2=A0=20?= =?UTF-8?q?=EC=97=AD=EC=9D=98=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/SubwayService.java | 6 ++++++ src/main/java/subway/domain/LineRepository.java | 4 ++++ src/main/java/subway/domain/StationRepository.java | 4 ++++ src/test/java/subway/SubwayServiceTest.java | 13 +++++++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/subway/SubwayService.java b/src/main/java/subway/SubwayService.java index e329cc54c..60761a175 100644 --- a/src/main/java/subway/SubwayService.java +++ b/src/main/java/subway/SubwayService.java @@ -5,6 +5,8 @@ import subway.domain.Station; import subway.domain.StationRepository; +import java.util.List; + public class SubwayService { public void addStation(String name) { @@ -23,4 +25,8 @@ public void addLine(String name, String[] stationNames) { } LineRepository.addLine(line); } + + public List getStations() { + return StationRepository.stations(); + } } diff --git a/src/main/java/subway/domain/LineRepository.java b/src/main/java/subway/domain/LineRepository.java index 49132ddb6..1891b368c 100644 --- a/src/main/java/subway/domain/LineRepository.java +++ b/src/main/java/subway/domain/LineRepository.java @@ -19,4 +19,8 @@ public static void addLine(Line line) { public static boolean deleteLineByName(String name) { return lines.removeIf(line -> Objects.equals(line.getName(), name)); } + + public static void clear() { + lines.clear(); + } } diff --git a/src/main/java/subway/domain/StationRepository.java b/src/main/java/subway/domain/StationRepository.java index 4b364200c..71d344da5 100644 --- a/src/main/java/subway/domain/StationRepository.java +++ b/src/main/java/subway/domain/StationRepository.java @@ -26,4 +26,8 @@ public static boolean deleteStation(String name) { public static boolean isStationExist(String name) { return stations.stream().anyMatch(station -> station.getName().equals(name)); } + + public static void clear() { + stations.clear(); + } } diff --git a/src/test/java/subway/SubwayServiceTest.java b/src/test/java/subway/SubwayServiceTest.java index e18ab9193..09dfa4a2c 100644 --- a/src/test/java/subway/SubwayServiceTest.java +++ b/src/test/java/subway/SubwayServiceTest.java @@ -7,8 +7,7 @@ import subway.domain.LineRepository; import subway.domain.StationRepository; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class SubwayServiceTest { SubwayService subwayService; @@ -16,6 +15,8 @@ public class SubwayServiceTest { @BeforeEach void setUp() { subwayService = new SubwayService(); + StationRepository.clear(); + LineRepository.clear(); } @Nested @@ -41,5 +42,13 @@ void duplicationStation() { void invalidStationName() { assertThrows(IllegalArgumentException.class, () -> subwayService.addStation("짱")); } + + @Test + @DisplayName("지하철 역의 목록을 조회할 수 있다.") + void getStations() { + subwayService.addStation("잠실역"); + subwayService.addStation("강남역"); + assertEquals(2, subwayService.getStations().size()); + } } }