feat: MovieServiceImplTest - test code for checking if exceptions occur
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
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.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.movie.domain.Movie;
|
||||
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
||||
import com.ticketing.server.movie.service.dto.DeletedMovieDTO;
|
||||
@@ -15,6 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.hibernate.sql.Delete;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -86,6 +89,24 @@ public class MovieServiceImplTest {
|
||||
assertTrue(registeredMovieDto.getTitle().equals(title));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Movie Service Test - register movie when there is same movie already")
|
||||
void shouldThrowExceptionWhenRegistering() {
|
||||
// given
|
||||
String title = "이미 중복된 영화 제목";
|
||||
|
||||
Movie movie = new Movie(title, 100L);
|
||||
|
||||
when(movieRepository.findValidMovieWithTitle(title))
|
||||
.thenReturn(Optional.of(movie));
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> movieService.registerMovie(title, 100L))
|
||||
.isInstanceOf(TicketingException.class);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Movie Service Test - delete movie")
|
||||
void shouldAbleToDeleteMovie() {
|
||||
@@ -104,4 +125,16 @@ public class MovieServiceImplTest {
|
||||
assertThat(deletedMovieDto.getDeletedAt()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Movie Service Test - delete movie when there is no such movie")
|
||||
void shouldThrowExceptionWhenDeleting() {
|
||||
// given
|
||||
when(movieRepository.findByIdAndDeletedAtNull(1L))
|
||||
.thenReturn(Optional.empty());
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> movieService.deleteMovie(1L))
|
||||
.isInstanceOf(TicketingException.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user