Skip to content

Commit fb922f2

Browse files
feat(list): added list of object example
1 parent fead18b commit fb922f2

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package de.claudioaltamura.java.restassured;
2+
3+
import java.util.Date;
4+
5+
public record Film(
6+
String title,
7+
String episode_id,
8+
String opening_crawl,
9+
String director,
10+
String producer,
11+
Date release_date,
12+
String[] species,
13+
String[] starships,
14+
String[] vehicles,
15+
String[] characters,
16+
String[] planets,
17+
String url,
18+
Date created,
19+
Date edited) {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package de.claudioaltamura.java.restassured;
2+
3+
import java.util.Collection;
4+
5+
public record Films(int count, Film next, Film previous, Collection<Film> results) {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package de.claudioaltamura.java.restassured;
2+
3+
import static io.restassured.RestAssured.get;
4+
import static org.assertj.core.api.Assertions.assertThat;
5+
6+
import io.restassured.common.mapper.TypeRef;
7+
import org.junit.jupiter.api.Test;
8+
9+
class ListOfObjectsTest {
10+
11+
@Test
12+
void shouldResponseAllFilmsAnd200() {
13+
var films =
14+
get("http://swapi.dev/api/films/?format=json")
15+
.then()
16+
.statusCode(200)
17+
.extract()
18+
.as(new TypeRef<Films>() {});
19+
20+
assertThat(films.count()).isEqualTo(6);
21+
assertThat(films.results())
22+
.extracting(Film::title)
23+
.contains(
24+
"A New Hope",
25+
"The Empire Strikes Back",
26+
"Return of the Jedi",
27+
"The Phantom Menace",
28+
"Attack of the Clones",
29+
"Revenge of the Sith");
30+
}
31+
}

0 commit comments

Comments
 (0)