Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2a54c65
docs: 기능 구현 목록 정리
soulgchoi May 4, 2021
1bff461
feat: 패키지 분리
soulgchoi May 4, 2021
064a128
feat: 역 생성할 때 중복 이름 확인
soulgchoi May 4, 2021
818abb4
feat: 역 삭제 기능 추가
soulgchoi May 4, 2021
370500a
docs: 구현된 기능 업데이트
soulgchoi May 4, 2021
f02b2a4
feat: 지하철 노선 생성
soulgchoi May 4, 2021
df6aeaa
feat: 지하철 노선 목록 조회
soulgchoi May 4, 2021
f605c88
feat: 지하철 노선 조회
soulgchoi May 4, 2021
486d819
fix: StationController 오타 수정, 테스트 케이스 교체
soulgchoi May 4, 2021
2a1b572
feat: ExceptionController 추가
soulgchoi May 5, 2021
1e110f1
feat: 지하철 노선 수정
soulgchoi May 5, 2021
23118a7
feat: 지하철 노선 삭제
soulgchoi May 5, 2021
7364ae3
docs: 2단계 기능 구현 목록 추가
soulgchoi May 5, 2021
86b9351
feat: 스프링 빈 적용
soulgchoi May 5, 2021
fe31f29
feat: LineDao JDBC 적용
soulgchoi May 5, 2021
883c428
feat: LineDao JDBC 적용
soulgchoi May 5, 2021
142d57b
StationDao JDBC 적용
soulgchoi May 5, 2021
e540ef2
refactor: 패키지 구조 변경
soulgchoi May 5, 2021
93f96e9
feat: LineDAO 테스트 추가
xlffm3 May 5, 2021
13a08e1
feat: StationDao 테스트 추가
xlffm3 May 5, 2021
985b109
feat: LineService 테스트 추가
xlffm3 May 5, 2021
324a78c
feat: StationService 테스트 추가
xlffm3 May 5, 2021
894b2c5
refactor: ExceptionController 메서드명 변경
xlffm3 May 5, 2021
aca42e2
refactor: LineAcceptanceTest 테스트 전후 실행 메서드 추가
xlffm3 May 5, 2021
e3d6fef
feat: StationAcceptanceTest 중복 제거 및 별도의 profile 추가
xlffm3 May 5, 2021
367ff3b
refactor: Controller uri 중복되는 부분 requestMapping으로 분리
xlffm3 May 5, 2021
5c8872e
feat: H2 trace 기능 추가
xlffm3 May 6, 2021
4041127
refactor: Controller 메서드 체이닝 개행 및 uri 변수 추출
xlffm3 May 6, 2021
3181a45
refactor: LineController 응답 본문이 없는 경우 noContent 반환
xlffm3 May 6, 2021
1930986
refactor: LineResponse 정적 팩토리 메서드 추가
xlffm3 May 6, 2021
16df0e5
style: LineController test 메서드 체이닝 개행 적용
xlffm3 May 6, 2021
dde81a3
refactor: StationResponse 정적 팩토리 메서드 추가
xlffm3 May 6, 2021
6258b2a
refactor: Station과 Line id를 Long 래퍼 클래스로 변환
xlffm3 May 6, 2021
fdbb82c
refactor: dao 애스터리스크 삭제 및 칼럼명 직접 참조
xlffm3 May 6, 2021
d9476a4
refactor: dao 로직에서 커스텀 예외 호출 및 전역 예외 핸들러가 처리하도록 변경
xlffm3 May 7, 2021
f2cbbf2
refactor: LineDao 테스트 계층 적용
xlffm3 May 7, 2021
86521f8
refactor: StationDao 테스트 계층 적용
xlffm3 May 7, 2021
5fb6f95
refactor: 불필요한 Service test 삭제
xlffm3 May 7, 2021
1b714be
fix: update 메서드 유일키 중복 예외 핸들 추가
xlffm3 May 7, 2021
20278c2
feat: update 메서드 key 중복 예외 추가
xlffm3 May 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: LineDao 테스트 계층 적용
  • Loading branch information
xlffm3 committed May 7, 2021
commit f2cbbf2435a57967204f112937881553f80b4484
160 changes: 129 additions & 31 deletions src/test/java/wooteco/subway/dao/LineDaoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest;
import org.springframework.jdbc.core.JdbcTemplate;
import wooteco.subway.domain.line.Line;
import wooteco.subway.exception.ExceptionStatus;
import wooteco.subway.exception.SubwayException;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
Expand All @@ -29,47 +34,140 @@ void setUp() {
testLineId = lineDao.save(new Line("testLine", "white"));
}

@DisplayName("노선을 등록한다.")
@Test
void save() {
Line line = new Line("testLine2", "black");
lineDao.save(line);
assertThatCode(() -> lineDao.save(line)).isInstanceOf(IllegalArgumentException.class);
// lineDao.save(line);
// lineDao.save(line);
// List<Line> lines = lineDao.findAll();
//
// assertThat(lines).hasSize(2);
@Nested
@DisplayName("save 메서드는")
class Describe_save {

@Nested
@DisplayName("이름이 중복되지 않은 엔티티의 경우")
class Context_with_unique_name {

@DisplayName("노선을 정상적으로 등록한다.")
@Test
void save() {
Line line = new Line("testLine2", "black");
lineDao.save(line);

List<Line> lines = lineDao.findAll();

assertThat(lines).hasSize(2);
}
}

@Nested
@DisplayName("이름이 중복된 경우")
class Context_with_duplicated_name {

@DisplayName("노선 등록에 실패한다.")
@Test
void cannotSave() {
Line line = new Line("testLine2", "black");
lineDao.save(line);

assertThatCode(() -> lineDao.save(line))
.isInstanceOf(SubwayException.class)
.hasMessage(ExceptionStatus.DUPLICATED_NAME.getMessage());
}
}
}

@DisplayName("노선을 ID로 조회한다.")
@Test
void findById() {
Line line = lineDao.findById(testLineId);
@Nested
@DisplayName("findById 메서드는")
class Describe_findById {

@Nested
@DisplayName("id에 해당하는 엔티티가 존재하는 경우")
class Context_with_valid_id {

@DisplayName("노선 조회에 성공한다.")
@Test
void findById() {
Line line = lineDao.findById(testLineId);

assertThat(line).isEqualTo(new Line(testLineId, "testLine", "white"));
assertThat(line).isEqualTo(new Line(testLineId, "testLine", "white"));
}
}

@Nested
@DisplayName("id에 해당하는 엔티티가 없는 경우")
class Context_with_invalid_id {

@DisplayName("노선 조회에 실패한다.")
@Test
void cannotFindById() {
assertThatCode(() -> lineDao.findById(6874))
.isInstanceOf(SubwayException.class)
.hasMessage(ExceptionStatus.ID_NOT_FOUND.getMessage());
}
}
}

@DisplayName("노선의 정보를 수정한다.")
@Test
void update() {
lineDao.update(testLineId, "changedName", "grey");
@Nested
@DisplayName("update 메서드는")
class Describe_update {

@Nested
@DisplayName("id에 해당하는 엔티티가 존재하는 경우")
class Context_with_valid_id {

@DisplayName("노선 수정에 성공한다.")
@Test
void update() {
lineDao.update(testLineId, "changedName", "grey");

Line line = lineDao.findById(testLineId);

Line line = lineDao.findById(testLineId);
assertThat(line.getName()).isEqualTo("changedName");
assertThat(line.getColor()).isEqualTo("grey");
}
}

assertThat(line.getName()).isEqualTo("changedName");
assertThat(line.getColor()).isEqualTo("grey");
@Nested
@DisplayName("id에 해당하는 엔티티가 존재하지 않는 경우")
class Context_with_invalid_id {

@DisplayName("노선 수정에 실패한다.")
@Test
void cannotUpdate() {
assertThatCode(() -> lineDao.update(6874, "rrr", "yellow"))
.isInstanceOf(SubwayException.class)
.hasMessage(ExceptionStatus.ID_NOT_FOUND.getMessage());
}
}
}

@DisplayName("노선을 삭제한다.")
@Test
void delete() {
long id = lineDao.save(new Line("dummy", "blue"));
int beforeLineCounts = lineDao.findAll().size();
@Nested
@DisplayName("deleteById 메서드는")
class Describe_deleteById {

@Nested
@DisplayName("id에 해당하는 엔티티가 존재하는 경우")
class Context_with_valid_id {

@DisplayName("노선 삭제에 성공한다.")
@Test
void deleteById() {
long id = lineDao.save(new Line("dummy", "blue"));
int beforeLineCounts = lineDao.findAll().size();

lineDao.deleteById(id);
int afterLineCounts = lineDao.findAll().size();

assertThat(beforeLineCounts - 1).isEqualTo(afterLineCounts);
}
}

lineDao.deleteById(id);
int afterLineCounts = lineDao.findAll().size();
@Nested
@DisplayName("id에 해당하는 엔티티가 존재하지 않는 경우")
class Context_with_invalid_id {

assertThat(beforeLineCounts - 1).isEqualTo(afterLineCounts);
@DisplayName("노선 삭제에 실패한다.")
@Test
void cannotUpdate() {
assertThatCode(() -> lineDao.deleteById(6874))
.isInstanceOf(SubwayException.class)
.hasMessage(ExceptionStatus.ID_NOT_FOUND.getMessage());
}
}
}
}