Repository navigation
[FIX] 코드 예시 noteNumbers 불변 리스트로 반환 #202
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b6733b
fix: 코드 예시 noteNumbers 불변 리스트로 반환 (#201)
p1001q d659b41
fix: noteNumbers 필드 즉시 초기화로 null 안전성 보완 (#201)
p1001q 9884cd2
Merge branch 'develop' of https://github.com/Musereview/BE into fix/#…
p1001q 23dc668
fix: noteNumbers 필드 초기화 되돌림 + Home 테스트 시간대 수정 (#201)
p1001q 26175a4
fix: noteNumbers 필드 즉시 초기화 재반영 (#201)
p1001q 1e733e7
test: 노트 번호 회귀 테스트가 세션 종료 후 접근을 재현하도록 트랜잭션 범위 분리 (#201)
p1001q File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
70 changes: 70 additions & 0 deletions
70
src/test/java/com/mr/domain/learning/service/ChordExampleNoteNumbersIntegrationTest.java
This file contains hidden or 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,70 @@ | ||
| package com.mr.domain.learning.service; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import com.mr.domain.learning.dto.res.LearningStepDetailResponseDTO; | ||
| import com.mr.domain.learning.entity.ChordExample; | ||
| import com.mr.domain.learning.entity.Learning; | ||
| import com.mr.domain.learning.entity.LearningStep; | ||
| import com.mr.domain.learning.entity.enums.LearningCategory; | ||
| import com.mr.domain.learning.entity.enums.LearningDifficulty; | ||
| import com.mr.domain.learning.repository.ChordExampleRepository; | ||
| import com.mr.domain.learning.repository.LearningRepository; | ||
| import com.mr.domain.learning.repository.LearningStepRepository; | ||
| import jakarta.persistence.EntityManager; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| /** | ||
| * 서승기님이 지적한 서버 크래시 재현/검증용 통합 테스트. | ||
| * noteNumbers는 @ElementCollection이라 실제로는 Hibernate가 관리하는 컬렉션(PersistentBag)으로 로드되는데, | ||
| * Mockito mock(ChordExample.class)로는 이 타입을 재현할 수 없어 flush+clear로 영속성 컨텍스트를 비우고 | ||
| * 실제로 DB에서 다시 읽어온 컬렉션으로 검증한다. | ||
| */ | ||
| @SpringBootTest | ||
| @Transactional | ||
|
p1001q marked this conversation as resolved.
Resolved
|
||
| class ChordExampleNoteNumbersIntegrationTest { | ||
|
|
||
| @Autowired | ||
| private LearningService learningService; | ||
| @Autowired | ||
| private LearningRepository learningRepository; | ||
| @Autowired | ||
| private LearningStepRepository learningStepRepository; | ||
| @Autowired | ||
| private ChordExampleRepository chordExampleRepository; | ||
| @Autowired | ||
| private EntityManager entityManager; | ||
|
|
||
| @Test | ||
| @DisplayName("getStepDetail - 실제 Hibernate 컬렉션으로 로드된 noteNumbers도 불변 리스트로 반환된다") | ||
| void getStepDetail_realHibernateCollection_returnsImmutableNoteNumbers() { | ||
| Learning learning = learningRepository.save(Learning.create( | ||
| "Tension Notes", LearningCategory.THEORY, LearningDifficulty.ADVANCED, | ||
| "요약", "본문", "팁", 10, "PIANO", true)); | ||
|
|
||
| LearningStep step = learningStepRepository.save( | ||
| LearningStep.create(learning, 1, "11th 텐션 노트 활용하기", "설명", "이론 설명", "연습 팁", 10)); | ||
|
|
||
| chordExampleRepository.save( | ||
| ChordExample.create(step, "Cmaj7", List.of(4, 11), "F(11th) 주의 - E(3rd)와 충돌")); | ||
|
|
||
| // 방금 만든 자바 객체가 아니라 DB에서 진짜로 다시 읽어온 Hibernate 컬렉션을 태우기 위해 영속성 컨텍스트를 비운다 | ||
| entityManager.flush(); | ||
| entityManager.clear(); | ||
|
|
||
| LearningStepDetailResponseDTO.StepDetailResultDTO result = | ||
| learningService.getStepDetail(learning.getId(), step.getId()); | ||
|
|
||
| assertThat(result.chordExamples()).hasSize(1); | ||
| List<Integer> noteNumbers = result.chordExamples().get(0).noteNumbers(); | ||
| assertThat(noteNumbers).containsExactly(4, 11); | ||
| assertThatThrownBy(() -> noteNumbers.add(1)) | ||
| .isInstanceOf(UnsupportedOperationException.class); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.