Compare commits

..

3 Commits

Author SHA1 Message Date
손창현
d431388c1b Merge branch 'develop' of https://github.com/f-lab-edu/Ticketing into feature/MovieTimeRegisterTest 2022-07-20 01:15:16 +09:00
Kim DongHyo
b3842d93b4 [User] 유저 컨트롤러 API 통합테스트 작성 (#84)
* test: 유저 통합테스트 추가

* test: JwtFilter 테스트케이스 추가

* refactor: 매직넘버 제거

* refactor: 회원탈퇴 / 패스워드 변경 검증 로직 수정
2022-07-20 01:06:22 +09:00
손창현
c9f5e69b4a feat: MovieTimeServiceTest - test registering movie time 2022-07-19 20:18:11 +09:00
2 changed files with 85 additions and 2 deletions

View File

@@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
import com.ticketing.server.global.exception.TicketingException;

View File

@@ -1,15 +1,23 @@
package com.ticketing.server.movie.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.any;
import com.ticketing.server.global.exception.TicketingException;
import com.ticketing.server.movie.domain.Movie;
import com.ticketing.server.movie.domain.MovieTime;
import com.ticketing.server.movie.domain.Theater;
import com.ticketing.server.movie.domain.repository.MovieRepository;
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
import com.ticketing.server.movie.domain.repository.TheaterRepository;
import com.ticketing.server.movie.service.dto.MovieTimeDTO;
import com.ticketing.server.movie.service.dto.MovieTimeRegisterDTO;
import com.ticketing.server.movie.service.dto.RegisteredMovieTimeDTO;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -27,11 +35,15 @@ import org.mockito.junit.jupiter.MockitoExtension;
public class MovieTimeServiceImplTest {
String title = "범죄도시2";
LocalDateTime startAt = LocalDateTime.now();
List<MovieTime> movieTimes = new ArrayList<>();
@Mock
MovieRepository movieRepository;
@Mock
TheaterRepository theaterRepository;
@Mock
MovieTimeRepository movieTimeRepository;
@@ -39,7 +51,7 @@ public class MovieTimeServiceImplTest {
MovieTimeServiceImpl movieTimeService;
@Test
@DisplayName("MovieTime Service Test - get empty list when there are no valid movie times")
@DisplayName("MovieTime Service Test - get empty list when there is no valid movie time")
void shouldGetEmptyList() {
// given
Movie movie = new Movie(title, 106L);
@@ -82,4 +94,76 @@ public class MovieTimeServiceImplTest {
assertTrue(!movieTimeDtos.isEmpty());
}
@Test
@DisplayName("MovieTime Service Test - register movie time")
void shouldAbleToRegisterMovieTime() {
// given
Movie movie = new Movie(title, 100L);
Theater theater = new Theater(1);
MovieTime movieTime = new MovieTime(movie, theater, 1, startAt);
when(movieRepository.findByIdAndDeletedAtNull(anyLong()))
.thenReturn(Optional.of(movie));
when(theaterRepository.findByTheaterNumber(anyInt()))
.thenReturn(Optional.of(theater));
when(movieTimeRepository.findByMovieAndTheaterAndRoundAndDeletedAtNull(any(), any(), anyInt()))
.thenReturn(Optional.empty());
when(movieTimeRepository.save(any()))
.thenReturn(movieTime);
// when
RegisteredMovieTimeDTO registeredMovieTimeDto =
movieTimeService.registerMovieTime(
new MovieTimeRegisterDTO(1L, 1, 1, startAt)
);
// then
assertThat(registeredMovieTimeDto).isNotNull();
assertTrue(registeredMovieTimeDto.getTheaterNumber() == 1);
assertTrue(registeredMovieTimeDto.getStartAt() == startAt);
assertTrue(registeredMovieTimeDto.getRound() == 1);
}
@Test
@DisplayName("MovieTime Service Test - register movie time when there is same movie time already")
void shouldThrowExceptionWhenRegisteringDuplicateMovieTime() {
// given
Movie movie = new Movie(title, 100L);
Theater theater = new Theater(1);
MovieTime movieTime = new MovieTime(movie, theater, 1, startAt);
MovieTimeRegisterDTO movieTimeRegisterDto = new MovieTimeRegisterDTO(1L, 1, 1, startAt);
when(movieRepository.findByIdAndDeletedAtNull(anyLong()))
.thenReturn(Optional.of(movie));
when(theaterRepository.findByTheaterNumber(anyInt()))
.thenReturn(Optional.of(theater));
when(movieTimeRepository.findByMovieAndTheaterAndRoundAndDeletedAtNull(any(), any(), anyInt()))
.thenReturn(Optional.of(movieTime));
// when
// then
assertThatThrownBy(() -> movieTimeService.registerMovieTime(movieTimeRegisterDto))
.isInstanceOf(TicketingException.class);
}
@Test
@DisplayName("MovieTime Service Test - register movie time when there is no such movie")
void shouldThrowExceptionWhenRegisteringMovieTimeWithNoSuchMovie() {
// given
Theater theater = new Theater(1);
MovieTimeRegisterDTO movieTimeRegisterDto = new MovieTimeRegisterDTO(1L, 1, 1, startAt);
when(movieRepository.findByIdAndDeletedAtNull(1L))
.thenReturn(Optional.empty());
// when
// then
assertThatThrownBy(() -> movieTimeService.registerMovieTime(movieTimeRegisterDto))
.isInstanceOf(TicketingException.class);
}
}