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()); + } } }