Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -30,6 +31,7 @@
import com.baeldung.restassured.model.Movie;
import com.baeldung.restassured.service.AppService;

import io.restassured.common.mapper.TypeRef;
import io.restassured.response.Response;

@RunWith(SpringRunner.class)
Expand Down Expand Up @@ -78,7 +80,7 @@ public void givenMovieId_whenMakingGetRequestToMovieEndpoint_thenReturnMovie() {
}

@Test
public void whenCallingMoviesEndpoint_thenReturnAllMovies() {
public void givenSetMovie_whenCallingMoviesEndpoint_thenReturnAllMovies() {

Set<Movie> movieSet = new HashSet<>();
movieSet.add(new Movie(1, "movie1", "summary1"));
Expand All @@ -96,6 +98,22 @@ public void whenCallingMoviesEndpoint_thenReturnAllMovies() {
.as(Movie[].class);
assertThat(movies.length).isEqualTo(2);
}

@Test
public void whenCallingMoviesEndpoint_thenReturnAllMoviesAsList() {
Set<Movie> movieSet = new HashSet<>();
movieSet.add(new Movie(1, "movie1", "summary1"));
movieSet.add(new Movie(2, "movie2", "summary2"));
when(appService.getAll()).thenReturn(movieSet);

List<Movie> movies = get(uri + "/movies").then()
.statusCode(200)
.extract()
.as(new TypeRef<List<Movie>>() {});

assertThat(movies.size()).isEqualTo(2);
assertThat(movies).usingFieldByFieldElementComparator().containsAll(movieSet);
}

@Test
public void givenMovie_whenMakingPostRequestToMovieEndpoint_thenCorrect() {
Expand Down