-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from DayByQuest/test/interestService
[Test] 관심사 서비스 테스트를 작성한다
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/test/java/daybyquest/interest/application/GetInterestsServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package daybyquest.interest.application; | ||
|
||
import static daybyquest.support.fixture.InterestFixtures.INTEREST_1; | ||
import static daybyquest.support.fixture.InterestFixtures.INTEREST_2; | ||
import static daybyquest.support.fixture.InterestFixtures.INTEREST_3; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import daybyquest.interest.dto.response.InterestResponse; | ||
import daybyquest.interest.dto.response.MultiInterestResponse; | ||
import daybyquest.support.test.ServiceTest; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class GetInterestsServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private GetInterestsService getInterestsService; | ||
|
||
@Test | ||
void 관심사들을_조회한다() { | ||
// given | ||
interests.save(INTEREST_1.생성()); | ||
interests.save(INTEREST_2.생성()); | ||
interests.save(INTEREST_3.생성()); | ||
final List<String> expected = List.of(INTEREST_1.name, INTEREST_2.name, INTEREST_3.name); | ||
|
||
// when | ||
final MultiInterestResponse response = getInterestsService.invoke(); | ||
final List<String> actual = response.interests().stream().map(InterestResponse::name) | ||
.toList(); | ||
|
||
// then | ||
assertThat(actual).containsExactlyInAnyOrderElementsOf(expected); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/java/daybyquest/interest/application/SaveInterestServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package daybyquest.interest.application; | ||
|
||
import static daybyquest.support.fixture.InterestFixtures.INTEREST_1; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import daybyquest.interest.domain.Interest; | ||
import daybyquest.interest.dto.request.SaveInterestRequest; | ||
import daybyquest.support.test.ServiceTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public class SaveInterestServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private SaveInterestService saveInterestService; | ||
|
||
@Test | ||
void 관심사를_생성한다() { | ||
// given | ||
final SaveInterestRequest request = 관심사_생성_요청(INTEREST_1.생성()); | ||
final MultipartFile file = 사진_파일(INTEREST_1.imageIdentifier); | ||
|
||
// when | ||
saveInterestService.invoke(request, file); | ||
final Interest actual = interests.findAll().stream() | ||
.filter(interest -> interest.getName().equals(INTEREST_1.name)) | ||
.findFirst().orElseThrow(); | ||
|
||
// then | ||
assertAll(() -> { | ||
assertThat(actual.getName()).isEqualTo(INTEREST_1.name); | ||
assertThat(actual.getImageIdentifier()).isEqualTo(INTEREST_1.imageIdentifier); | ||
}); | ||
} | ||
|
||
private SaveInterestRequest 관심사_생성_요청(final Interest interest) { | ||
final SaveInterestRequest request = new SaveInterestRequest(); | ||
ReflectionTestUtils.setField(request, "name", interest.getName()); | ||
return request; | ||
} | ||
} |