Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[김대겸] Step1 PR #837

Merged
merged 3 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 6 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,8 @@
<p align="center">
<img width="200px;" src="https://raw.githubusercontent.com/woowacourse/atdd-subway-admin-frontend/master/images/main_logo.png"/>
</p>
<p align="center">
<img alt="npm" src="https://img.shields.io/badge/npm-6.14.15-blue">
<img alt="node" src="https://img.shields.io/badge/node-14.18.2-blue">
<a href="https://edu.nextstep.camp/c/R89PYi5H" alt="nextstep atdd">
<img alt="Website" src="https://img.shields.io/website?url=https%3A%2F%2Fedu.nextstep.camp%2Fc%2FR89PYi5H">
</a>
<img alt="GitHub" src="https://img.shields.io/github/license/next-step/atdd-subway-admin">
</p>
# 인수 테스트 주도 개발

<br>
## 🚀 1단계 - 지하철역의 인수 테스트 작성

# 지하철 노선도 미션
[ATDD 강의](https://edu.nextstep.camp/c/R89PYi5H) 실습을 위한 지하철 노선도 애플리케이션

<br>

## 🚀 Getting Started

### Install
#### npm 설치
```
cd frontend
npm install
```
> `frontend` 디렉토리에서 수행해야 합니다.

### Usage
#### webpack server 구동
```
npm run dev
```
#### application 구동
```
./gradlew bootRun
```
<br>

## ✏️ Code Review Process
[텍스트와 이미지로 살펴보는 온라인 코드 리뷰 과정](https://github.com/next-step/nextstep-docs/tree/master/codereview)

<br>

## 🐞 Bug Report

버그를 발견한다면, [Issues](https://github.com/next-step/atdd-subway-admin/issues) 에 등록해주세요 :)

<br>

## 📝 License

This project is [MIT](https://github.com/next-step/atdd-subway-admin/blob/master/LICENSE.md) licensed.
### 기능 요구사항
-[X] 지하철역 관련 인수 테스트를 완성하세요.
-[X] 지하철역 목록 조회 인수 테스트 작성하기
-[X] 지하철역 삭제 인수 테스트 작성하기
115 changes: 93 additions & 22 deletions src/test/java/nextstep/subway/station/StationAcceptanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not;

@DisplayName("지하철역 관련 기능")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Expand All @@ -38,28 +40,34 @@ public void setUp() {
@DisplayName("지하철역을 생성한다.")
@Test
void createStation() {
//@formatter:off

Comment on lines +43 to +44

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매 테스트마다 이 설정이 들어간 것 같은데요 🤔
만약 정렬할 때 메서드 체이닝하는 부분이 인라인으로 자동 정렬되는 것이라면
Preferences -> Code style -> Formatter -> Reformat again to remove custom line breaks
체크가 제거되어 있는지 확인 한번만 부탁드릴게요 🙏

코드에 주석으로 설정을 추가해주는 것보다
설정된 코드 스타일을 export 하여 설정 파일을 공유하는 방향은 어떻게 생각하시나요?? 🤔🤔
Screenshot 2022-11-08 at 4 52 47 PM

Copy link
Author

@Gyeom Gyeom Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

체크가 제거되어 있는 상태라 메서드 체이닝 부분은 인라인으로 자동 정렬이되지는 않습니다.

image

다만 개인적으로 위에 첨부한 코드처럼 가독성이 너무 떨어진다고 판단하였고, 번거로움을 해소하기 위해서 Live Templates을 활용하고 있습니다.

image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 감사합니다!
대겸님 의도에 대해서 이해했습니다!

// when
Map<String, String> params = new HashMap<>();
params.put("name", "강남역");

ExtractableResponse<Response> response =
RestAssured.given().log().all()
.body(params)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when().post("/stations")
.then().log().all()
.extract();
RestAssured.given()
.log().all()
.body(params)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when().post("/stations")
.then().log().all()
.extract();

// then
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value());

// then
List<String> stationNames =
RestAssured.given().log().all()
.when().get("/stations")
.then().log().all()
.extract().jsonPath().getList("name", String.class);
RestAssured.given()
.log().all()
.when().get("/stations")
.then().log().all()
.extract().jsonPath().getList("name", String.class);
assertThat(stationNames).containsAnyOf("강남역");

//@formatter:on
}

/**
Expand All @@ -70,27 +78,27 @@ void createStation() {
@DisplayName("기존에 존재하는 지하철역 이름으로 지하철역을 생성한다.")
@Test
void createStationWithDuplicateName() {
//@formatter:off

// given
Map<String, String> params = new HashMap<>();
params.put("name", "강남역");

RestAssured.given().log().all()
.body(params)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when().post("/stations")
.then().log().all();
givenCreateStation(params);

// when
ExtractableResponse<Response> response =
RestAssured.given().log().all()
.body(params)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when().post("/stations")
.then().log().all()
.extract();
RestAssured.given()
.log().all()
.body(params)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when().post("/stations")
.then().log().all()
.extract();

// then
assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());

//@formatter:on
}

/**
Expand All @@ -101,6 +109,26 @@ void createStationWithDuplicateName() {
@DisplayName("지하철역을 조회한다.")
@Test
void getStations() {
//@formatter:off

// given
String station1 = "강남역";
String station2 = "종각역";
givenCreateStation(Map.of("name", station1));
givenCreateStation(Map.of("name", station2));
Comment on lines +117 to +118

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradle 의 자바 버전과 프로젝트의 자바 버전 설정 확인 한번만 부탁드리겠습니다. 🙏🙇‍♂️
gradle 에서는 자바 8로 설정되어 있을텐데
사용해주신 Map.of 는 자바 9 이상에서 사용할 수 있는 메소드 같아서요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞습니다~ㅠㅠ 다른 방법을 고민해보도록 하겠습니다!


// when & then
RestAssured.given()
.contentType(MediaType.APPLICATION_JSON_VALUE)
.log().all()
.when()
.get("/stations")
.then()
.statusCode(200)
.assertThat().body("name", hasItems(station1, station2))
.log().all();;

//@formatter:on
}

/**
Expand All @@ -111,5 +139,48 @@ void getStations() {
@DisplayName("지하철역을 제거한다.")
@Test
void deleteStation() {
//@formatter:off

// given
String station1 = "강남역";
givenCreateStation(Map.of("name", station1));

Comment on lines +144 to +147

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

같은 데이터를 계속 추가해주고 있는데
다른 테스트에 영향이 없는지 확인 한번만 부탁드리겠습니다.🙇‍♂️🙏
제 개인 환경에서는 전체 테스트가 중간에 깨지게 되네요 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 알겠습니다~! ㅎㅎ

// when
RestAssured.given()
.log().all()
.when()
.delete("/stations/1")
.then()
.statusCode(204)
.log().all();;


// then
RestAssured.given()
.contentType(MediaType.APPLICATION_JSON_VALUE)
.log().all()
.when()
.get("/stations")
.then()
.statusCode(200)
.assertThat().body("name", not(hasItems(station1)))
.log().all();

//@formatter:on
}

private void givenCreateStation(final Map<String, String> params) {
//@formatter:off

RestAssured.given()
.log().all()
.body(params)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when()
.post("/stations")
.then()
.log().all();

//@formatter:on
}
}