-
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.
- StyleService 테스트 작성 - StyleFakeRepository 작성 - StyleService 메서드 이름 수정
- Loading branch information
1 parent
18db8df
commit e58e6b2
Showing
3 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
src/test/java/com/atwoz/member/application/info/StyleServiceTest.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,72 @@ | ||
package com.atwoz.member.application.info; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.atwoz.member.application.info.style.StyleService; | ||
import com.atwoz.member.domain.info.style.Style; | ||
import com.atwoz.member.domain.info.style.StyleRepository; | ||
import com.atwoz.member.infrastructure.info.StyleFakeRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import java.util.List; | ||
|
||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
@ExtendWith(MockitoExtension.class) | ||
public class StyleServiceTest { | ||
|
||
private StyleService styleService; | ||
private StyleRepository styleRepository; | ||
|
||
@BeforeEach | ||
void init() { | ||
styleRepository = new StyleFakeRepository(); | ||
styleService = new StyleService(styleRepository); | ||
} | ||
|
||
@Test | ||
void 회원의_모든_스타일을_저장한다() { | ||
// given | ||
Long memberId = 1L; | ||
List<String> styleNames = List.of("긍정적", "유머 감각"); | ||
|
||
// when | ||
styleService.saveMemberStyles(memberId, styleNames); | ||
|
||
// then | ||
List<Style> saveStyles = styleRepository.findAllByMemberId(memberId); | ||
assertThat(saveStyles.size()).isEqualTo(2); | ||
} | ||
|
||
@Test | ||
void 회원의_모든_스타일을_삭제한다() { | ||
// given | ||
Long memberId = 1L; | ||
List<String> styleNames = List.of("긍정적", "유머 감각"); | ||
styleService.saveMemberStyles(memberId, styleNames); | ||
|
||
// when | ||
styleService.deleteMemberStyles(memberId); | ||
|
||
// then | ||
assertThat(styleRepository.findAllByMemberId(memberId)).isEmpty(); | ||
} | ||
|
||
@Test | ||
void 회원의_모든_스타일을_조회한다() { | ||
// given | ||
Long memberId = 1L; | ||
List<String> styleNames = List.of("긍정적", "유머 감각"); | ||
styleService.saveMemberStyles(memberId, styleNames); | ||
|
||
// when | ||
List<Style> memberStyles = styleService.findMemberStyles(memberId); | ||
|
||
// then | ||
assertThat(memberStyles.size()).isEqualTo(2); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/com/atwoz/member/infrastructure/info/StyleFakeRepository.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,40 @@ | ||
package com.atwoz.member.infrastructure.info; | ||
|
||
import com.atwoz.member.domain.info.style.Style; | ||
import com.atwoz.member.domain.info.style.StyleRepository; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class StyleFakeRepository implements StyleRepository { | ||
|
||
private final Map<Long, Style> map = new HashMap<>(); | ||
private long id = 1L; | ||
|
||
@Override | ||
public void save(final Style style) { | ||
Style newStyle = new Style(style.getMemberId(), style.getStyleName()); | ||
map.put(id, newStyle); | ||
id++; | ||
} | ||
|
||
@Override | ||
public void saveAll(final List<Style> styles) { | ||
styles.stream() | ||
.map(style -> new Style(style.getMemberId(), style.getStyleName())) | ||
.forEach(style -> map.put(id++, style)); | ||
} | ||
|
||
@Override | ||
public void deleteStylesByMemberId(final Long memberId) { | ||
map.values().removeIf(style -> memberId.equals(style.getMemberId())); | ||
} | ||
|
||
@Override | ||
public List<Style> findAllByMemberId(final Long memberId) { | ||
return map.values() | ||
.stream() | ||
.filter(style -> memberId.equals(style.getMemberId())) | ||
.toList(); | ||
} | ||
} |