Skip to content

Commit

Permalink
지하철 등록 techeer-sv#3 feat : 지하철 역의 목록 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
heondong9265 committed May 31, 2024
1 parent f29614b commit 2afd419
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/subway/SubwayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import subway.domain.Station;
import subway.domain.StationRepository;

import java.util.List;

public class SubwayService {

public void addStation(String name) {
Expand All @@ -23,4 +25,8 @@ public void addLine(String name, String[] stationNames) {
}
LineRepository.addLine(line);
}

public List<Station> getStations() {
return StationRepository.stations();
}
}
4 changes: 4 additions & 0 deletions src/main/java/subway/domain/LineRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 4 additions & 0 deletions src/main/java/subway/domain/StationRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
13 changes: 11 additions & 2 deletions src/test/java/subway/SubwayServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
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;

@BeforeEach
void setUp() {
subwayService = new SubwayService();
StationRepository.clear();
LineRepository.clear();
}

@Nested
Expand All @@ -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());
}
}
}

0 comments on commit 2afd419

Please sign in to comment.