Skip to content

Commit

Permalink
test: GET /depts 테스트 코드 수정
Browse files Browse the repository at this point in the history
1. 기존에 연관관계를 테스트하지 않던 코드 수정
2. 반복문을 제거하고 일일이 매핑하도록 수정
  • Loading branch information
songsunkook committed Jan 4, 2024
1 parent 77c5c32 commit 29cca20
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions src/test/java/in/koreatech/koin/acceptance/DeptApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import static org.assertj.core.api.SoftAssertions.assertSoftly;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -14,8 +10,8 @@
import in.koreatech.koin.AcceptanceTest;
import in.koreatech.koin.domain.dept.model.DeptInfo;
import in.koreatech.koin.domain.dept.model.DeptNum;
import in.koreatech.koin.domain.dept.repository.DeptNumRepository;
import in.koreatech.koin.domain.dept.repository.DeptInfoRepository;
import in.koreatech.koin.domain.dept.repository.DeptNumRepository;
import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
Expand Down Expand Up @@ -122,24 +118,13 @@ void findAllDepts() {
assertSoftly(
softly -> {
softly.assertThat(response.body().jsonPath().getList(".").size()).isEqualTo(DEPT_SIZE);

List<Boolean> deptNamesExists = Stream.generate(() -> false).limit(DEPT_SIZE).collect(Collectors.toList());
for (int i = 0; i < DEPT_SIZE; i++) {
if (response.body().jsonPath().getString("[" + i + "].name").equals(deptInfo1.getName())) {
deptNamesExists.set(i, true);
softly.assertThat(response.body().jsonPath().getString("["+ i + "].curriculum_link")).isEqualTo(
deptInfo1.getCurriculumLink());
softly.assertThat(response.body().jsonPath().getLong("[" + i + "].dept_nums[0]")).isEqualTo(deptNum1_1.getNumber());
softly.assertThat(response.body().jsonPath().getLong("[" + i + "].dept_nums[1]")).isEqualTo(deptNum1_2.getNumber());
}
if (response.body().jsonPath().getString("[" + i + "].name").equals(deptInfo2.getName())) {
deptNamesExists.set(i, true);
softly.assertThat(response.body().jsonPath().getString("[" + i + "].curriculum_link")).isEqualTo(
deptInfo2.getCurriculumLink());
softly.assertThat(response.body().jsonPath().getLong("[" + i + "].dept_nums[0]")).isEqualTo(deptNum2.getNumber());
}
}
softly.assertThat(deptNamesExists.contains(false)).isFalse();
softly.assertThat(response.body().jsonPath().getString("[0].name")).isEqualTo(deptInfo2.getName());
softly.assertThat(response.body().jsonPath().getString("[1].name")).isEqualTo(deptInfo1.getName());
softly.assertThat(response.body().jsonPath().getString("[0].curriculum_link")).isEqualTo(deptInfo2.getCurriculumLink());
softly.assertThat(response.body().jsonPath().getString("[1].curriculum_link")).isEqualTo(deptInfo1.getCurriculumLink());
softly.assertThat(response.body().jsonPath().getLong("[0].dept_nums[0]")).isEqualTo(deptInfo2.getDeptNums().get(0));
softly.assertThat(response.body().jsonPath().getLong("[1].dept_nums[0]")).isEqualTo(deptInfo1.getDeptNums().get(0));
softly.assertThat(response.body().jsonPath().getLong("[1].dept_nums[1]")).isEqualTo(deptInfo1.getDeptNums().get(1));
}
);
}
Expand Down

0 comments on commit 29cca20

Please sign in to comment.