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

๐Ÿš€ 1๋‹จ๊ณ„ - ์ง€ํ•˜์ฒ  ๊ตฌ๊ฐ„ ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ฐœ์„  #606

Open
wants to merge 15 commits into
base: jjisun
Choose a base branch
from

Conversation

jjisun
Copy link

@jjisun jjisun commented Jul 18, 2023

์ง€ํ•˜์ฒ  ๊ตฌ๊ฐ„ ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ฐœ์„  ๊ตฌํ˜„

  • ๊ธฐ์กด : ๊ตฌ๊ฐ„์€ ์ข…์ ์—์„œ๋งŒ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
  • ๋ณ€๊ฒฝ : ๊ตฌ๊ฐ„์€ ์•ž, ๋’ค, ์ค‘๊ฐ„ ๋ชจ๋‘ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
  • : ์ƒˆ๋กœ์šด ์—ญ์„ ์ƒํ–‰ ์ข…์ ์œผ๋กœ ๋“ฑ๋ก
  • : ์ƒˆ๋กœ์šด ์—ญ์„ ํ•˜ํ–‰ ์ข…์ ์œผ๋กœ ๋“ฑ๋ก
  • : ์—ญ ์‚ฌ์ด์— ์ƒˆ๋กœ์šด ์—ญ์„ ๋“ฑ๋ก
  • ์˜ˆ์™ธ ์กฐ๊ฑด
  • : ์—ญ ์‚ฌ์ด์— ์ƒˆ๋กœ์šด ์—ญ์„ ๋“ฑ๋กํ•  ๊ฒฝ์šฐ, ๊ฑฐ๋ฆฌ๋Š” ๊ธฐ์กด์˜ ๊ตฌ๊ฐ„๋ณด๋‹ค ์งง์•„์•ผ ํ•จ
  • : ์ƒํ–‰์—ญ๊ณผ ํ•˜ํ–‰์—ญ์ด ์ด๋ฏธ ๋…ธ์„ ์— ๋ชจ๋‘ ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค๋ฉด ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†์Œ
  • : ์ƒํ–‰์—ญ๊ณผ ํ•˜ํ–‰์—ญ ๋‘˜ ์ค‘ ํ•˜๋‚˜๋„ ํฌํ•จ๋˜์–ด์žˆ์ง€ ์•Š์œผ๋ฉด ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†์Œ

๋ฆฌ๋ทฐ ์ž˜๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค :)

boorownie and others added 15 commits January 17, 2022 03:01
* step1: ์ง€ํ•˜์ฒ  ๋ชฉ๋ก ์กฐํšŒ, ์ œ๊ฑฐ ์ธ์ˆ˜ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ

* 2๋‹จ๊ณ„ ์ง€ํ•˜์ฒ  ๋…ธ์„  ๊ด€๋ฆฌ
# Conflicts:
#	src/test/java/subway/acceptance/SectionAcceptanceTest.java
Copy link

@junwoochoi junwoochoi left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š”! 1๋‹จ๊ณ„ ๋ฏธ์…˜ ์ง„ํ–‰ํ•ด์ฃผ์‹  ๋ถ€๋ถ„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค!
0๋‹จ๊ณ„ ์‹ค์Šต์„ ๋†“์น˜๊ณ  ๊ณ„์‹  ๊ฒƒ ๊ฐ™์•„์„œ ์š” ๋ถ€๋ถ„ ํ™•์ธ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค ๐Ÿ™
์ถ”๊ฐ€๋กœ 2์ฃผ์ฐจ ์‹ค์Šต์€ ์ธ์ˆ˜ํ…Œ์ŠคํŠธ์™€ ๋‹จ์œ„ํ…Œ์ŠคํŠธ๋ฅผ ํ•จ๊ป˜ ํ•˜๋ฉด์„œ ๊ฐ•์˜์ค‘์— ๋‹ค๋ค˜๋˜ Outside In, Inside Out์ด ๊ฐ๊ฐ ์–ด๋–ค ์žฅ๋‹จ์ ์ด ์žˆ๋Š”์ง€, ์–ด๋–ค ๋ฐฉ์‹์ด ๋” ์„ ํ˜ธํ•˜๋Š” ๋ฐฉ์‹์— ๋งž๋Š”์ง€ ์ƒ๊ฐํ•ด๋ณด์‹œ๋ฉด์„œ ์ง„ํ–‰ํ•ด๋ณด์‹œ๋ฉด ๋” ์ข‹๋‹ต๋‹ˆ๋‹ค ๐Ÿ˜„
1๋‹จ๊ณ„ ๋ฏธ์…˜์— ๋Œ€ํ•œ ์ฝ”๋ฉ˜ํŠธ๋„ ๋‚จ๊ฒผ์œผ๋‹ˆ ํ•ด๋‹น ๋ถ€๋ถ„ + 0๋‹จ๊ณ„ ์‹ค์Šต ํ™•์ธ ํ›„ ๋‹ค์‹œ ์š”์ฒญ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!
์ถ”๊ฐ€๋กœ ์ดํ•ด๊ฐ€ ์•ˆ๋˜๋Š” ๋ถ€๋ถ„์ด๋‚˜ ์˜๋…ผํ•ด๋ณด๊ณ  ์‹ถ์€ ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ํŽธํ•˜๊ฒŒ dm์ด๋‚˜ ์ฑ„๋„์— ๋ฉ”์‹œ์ง€ ์ฃผ์„ธ์š”!

Comment on lines +25 to +35
@Transactional
public void execute() {
entityManager.flush();
entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY FALSE").executeUpdate();

for (String tableName : tableNames) {
entityManager.createNativeQuery("TRUNCATE TABLE " + tableName).executeUpdate();
}

entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY TRUE").executeUpdate();
}

Choose a reason for hiding this comment

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

์ธ์ˆ˜ํ…Œ์ŠคํŠธ ๊ฒฉ๋ฆฌ ๐Ÿ‘

import subway.fixture.StationFixture;

@DisplayName("์ง€ํ•˜์ฒ  ๊ตฌ๊ฐ„ ๊ด€๋ จ ๊ธฐ๋Šฅ")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)

Choose a reason for hiding this comment

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

RANDOM_PORT๋ฅผ ํ™œ์šฉํ•ด๋ณด๋ฉด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~

Comment on lines +31 to +44
@LocalServerPort
int port;

@Autowired
DatabaseCleaner databaseCleaner;

Long lineId;

Map<String, Long> stationMaps = new HashMap<>();

@BeforeEach
void setUp() {
RestAssured.port = port;
databaseCleaner.execute();

Choose a reason for hiding this comment

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

์•„๋ž˜ ๋ถ€๋ถ„๋“ค์ด ์ธ์ˆ˜ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค๋งˆ๋‹ค ๋ชจ๋‘ ์ค‘๋ณต์ด ๋ฐœ์ƒํ•˜๊ณ  ์žˆ๋Š”๋ฐ ์ค‘๋ณต์„ ์ค„์ผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์—†์„๊นŒ์š”?

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

 @LocalServerPort
    int port;

    @Autowired
    DatabaseCleaner databaseCleaner;
    
    @BeforeEach์˜  RestAssured.port = port;
        databaseCleaner.execute();

Comment on lines +99 to +100
var lineResponse = response.as(LineResponse.class);
assertThat(lineResponse.getStations().stream().map(StationResponse::getName)).containsAnyOf("์ •์ž์—ญ");

Choose a reason for hiding this comment

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

์ธ์ˆ˜ ํ…Œ์ŠคํŠธ๋Š” ๋ธ”๋ž™๋ฐ•์Šค ํ…Œ์ŠคํŠธ๋กœ ๋ณด๊ณ  ์ง„ํ–‰ํ•˜๋‹ˆ, ์ง์ ‘์ ์ธ ๊ตฌํ˜„์— ์˜์กด๋˜๋Š” as(LineResponse.class)๋ณด๋‹ค๋Š” jsonPath์œ„์ฃผ๋กœ ํ™œ์šฉํ•ด๋ณด์‹œ๊ธธ ๊ถŒํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค!
๋ฌผ๋ก  ๊ฐœ์ธ ์„ ํ˜ธ์— ๋”ฐ๋ผ ์ง€๊ธˆ์ฒ˜๋Ÿผ ๋ฐ”๋กœ ํด๋ž˜์Šค์— ๋งคํ•‘ํ•ด์„œ ํ™œ์šฉํ•ด์ฃผ์…”๋„ ์ข‹์Šต๋‹ˆ๋‹ค :)


// then
var lineResponse = response.as(LineResponse.class);
assertThat(lineResponse.getStations().stream().map(StationResponse::getName)).containsAnyOf("๋…ผํ˜„์—ญ");

Choose a reason for hiding this comment

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

์‘๋‹ต์— ๋…ผํ˜„์—ญ์ด ์žˆ๋Š”์ง€๋งŒ ํ™•์ธํ•˜๊ธฐ๋ณด๋‹ค ์ˆœ์„œ๋„ ์ฒดํฌํ•ด์ฃผ์‹œ๋ฉด ๋” ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค!

Comment on lines +76 to +97
if(o.getUpStation().equals(section.getUpStation())) {
replaceSections.add(section);
var distance = o.getDistance() - section.getDistance();
replaceSections.add(Section.builder()
.upStation(section.getDownStation())
.downStation(o.getDownStation())
.distance(distance)
.build());
} else if(o.getDownStation().equals(section.getDownStation())) {
var distance = o.getDistance() - section.getDistance();
replaceSections.add(Section.builder()
.upStation(o.getUpStation())
.downStation(section.getUpStation())
.distance(distance)
.build());
replaceSections.add(section);
} else {
replaceSections.add(o);
}
});

return replaceSections;

Choose a reason for hiding this comment

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

์š”๋ถ€๋ถ„ ๊ฐ€๋…์„ฑ์„ ๊ฐœ์„ ํ•ด๋ณผ ์ˆ˜ ์žˆ์„๊นŒ์š”?
๊ฐ์ฒด์ง€ํ–ฅ ์ƒํ™œ์ฒด์กฐ 2๋ฒˆ else์˜ˆ์•ฝ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋„ ์ฐธ๊ณ ํ•˜๋ฉด ๋„์›€์ด ๋˜๊ฒ ๋„ค์š”!

Comment on lines +116 to +122
public Section lastSection() {
return sections.get(sections.size() - 1);
}

public Section firstSection() {
return sections.get(0);
}

Choose a reason for hiding this comment

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

์ฒซ๋ฒˆ์งธ์™€ ๋งˆ์ง€๋ง‰ Section์€ index์ˆœ์œผ๋กœ ๊ฐ€์ ธ์™€์„œ๋Š” ์•Œ๋งž์€ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ํž˜๋“ญ๋‹ˆ๋‹ค. ์–ด๋–ค ์กฐ๊ฑด์˜ Station์ด ์ƒํ–‰, ํ•˜ํ–‰ ์ข…์ ์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ์„๊นŒ์š”?
image

}

public List<Station> stations() {
return this.sections.stream().map(o -> Arrays.asList(o.getUpStation(), o.getDownStation()))

Choose a reason for hiding this comment

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

image ์š”๊ธฐ์„œ๋„ ์œ„ ์ด๋ฏธ์ง€ ์ฐธ๊ณ ํ•˜์—ฌ ์ˆœ์„œ์— ๋งž๋Š” ์‘๋‹ต์„ ๋งŒ๋“ค์–ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค~!


import org.springframework.http.HttpStatus;

public class ApiException extends RuntimeException {

Choose a reason for hiding this comment

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

์ปค์Šคํ…€ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๐Ÿ‘


@ExceptionHandler(ApiException.class)
public ResponseEntity<ErrorResponse> handleSubwayException(ApiException apiException) {
return new ResponseEntity<>(ErrorResponse.builder()

Choose a reason for hiding this comment

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

๐Ÿ‘ ๐Ÿ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants