Skip to content

Commit

Permalink
fix : 정책 수정에 의한 테스트코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
moonn6pence committed Nov 10, 2023
1 parent a7315b1 commit e4d9101
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.ssafy.ssafsound.domain.member.exception.MemberErrorInfo;
import com.ssafy.ssafsound.domain.member.exception.MemberException;
import com.ssafy.ssafsound.domain.member.repository.MemberRepository;
import com.ssafy.ssafsound.domain.meta.domain.Campus;
import com.ssafy.ssafsound.domain.meta.domain.MetaData;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -50,6 +52,7 @@ class LunchPollServiceTest {
@InjectMocks
private LunchPollService lunchPollService;

private MetaData SEOUL;
private Lunch lunch1;
private Lunch lunch2;
private Lunch lunch3;
Expand All @@ -66,18 +69,23 @@ class LunchPollServiceTest {
@BeforeEach
void setUp() {

SEOUL = new MetaData(Campus.SEOUL);

lunch1 = Lunch.builder()
.id(1L)
.campus(SEOUL)
.createdAt(today)
.build();

lunch2 = Lunch.builder()
.id(2L)
.campus(SEOUL)
.createdAt(today)
.build();

lunch3 = Lunch.builder()
.id(3L)
.campus(SEOUL)
.createdAt(today.plusDays(1))
.build();

Expand Down Expand Up @@ -118,8 +126,8 @@ void Given_MemberIdAndLunchId_When_SaveLunchPoll_Then_Succeed(Long memberId, Lon
Integer expectedLunch2PollCount) {

// given
lenient().when(lunchPollRepository.findByMemberAndPolledAt(member1, today)).thenReturn(lunchPoll);
lenient().when(lunchPollRepository.findByMemberAndPolledAt(member2, today)).thenReturn(null);
lenient().when(lunchPollRepository.findByMemberAndCampusAndPolledAt(member1, SEOUL, today)).thenReturn(lunchPoll);
lenient().when(lunchPollRepository.findByMemberAndCampusAndPolledAt(member2, SEOUL, today)).thenReturn(null);

// when
PostLunchPollResDto postLunchPollResDto = lunchPollService.saveLunchPoll(memberId, lunchId);
Expand Down Expand Up @@ -167,13 +175,13 @@ void Given_AlreadyPolledLunchId_When_SaveLunchPoll_Then_ThrowException() {
// given
Long memberId = 1L;
Long lunchId = 2L;
given(lunchPollRepository.findByMemberAndPolledAt(member1, today)).willReturn(lunchPoll);
given(lunchPollRepository.findByMemberAndCampusAndPolledAt(member1, SEOUL, today)).willReturn(lunchPoll);

// when, then
LunchException exception = assertThrows(LunchException.class, () -> lunchPollService.saveLunchPoll(memberId, lunchId));
assertEquals(LunchErrorInfo.DUPLICATE_LUNCH_POLL, exception.getInfo());

verify(lunchPollRepository).findByMemberAndPolledAt(member1, today);
verify(lunchPollRepository).findByMemberAndCampusAndPolledAt(member1, SEOUL, today);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.ssafy.ssafsound.domain.lunch.dto.GetLunchListElementResDto;
import com.ssafy.ssafsound.domain.lunch.dto.GetLunchListReqDto;
import com.ssafy.ssafsound.domain.lunch.dto.GetLunchListResDto;
import com.ssafy.ssafsound.domain.lunch.exception.LunchErrorInfo;
import com.ssafy.ssafsound.domain.lunch.exception.LunchException;
import com.ssafy.ssafsound.domain.lunch.repository.LunchPollRepository;
import com.ssafy.ssafsound.domain.lunch.repository.LunchRepository;
import com.ssafy.ssafsound.domain.member.domain.Member;
Expand Down Expand Up @@ -36,8 +34,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.lenient;
Expand Down Expand Up @@ -112,9 +108,9 @@ void setUp() {
lenient().when(memberRepository.findById(1L)).thenReturn(Optional.of(member1));
lenient().when(memberRepository.findById(2L)).thenReturn(Optional.of(member2));

lenient().when(lunchPollRepository.findByMemberAndPolledAt(member1, today))
lenient().when(lunchPollRepository.findByMemberAndCampusAndPolledAt(member1, testCampus, today))
.thenReturn(lunchPoll);
lenient().when(lunchPollRepository.findByMemberAndPolledAt(member2, today))
lenient().when(lunchPollRepository.findByMemberAndCampusAndPolledAt(member2, testCampus, today))
.thenReturn(null);
}

Expand All @@ -132,7 +128,7 @@ void Given_DateAndCampus_When_FindLunches_Then_Succeed(
given(clock.getZone()).willReturn(ZoneId.of("Asia/Seoul"));

given(metaDataConsumer.getMetaData(MetaDataType.CAMPUS.name(), inputCampus))
.willReturn(new MetaData(Campus.SEOUL));
.willReturn(testCampus);

given(lunchRepository.findAllByCampusAndDate(
metaDataConsumer.getMetaData(MetaDataType.CAMPUS.name(), inputCampus), inputDate))
Expand Down

0 comments on commit e4d9101

Please sign in to comment.