Skip to content

Commit 96b17b2

Browse files
author
Mohamed
committed
Fix: modified the test
1 parent ba08b1e commit 96b17b2

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

lesson_16/api/api_app/src/test/java/com/codedifferently/lesson16/web/PatronControllerTest.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import com.codedifferently.lesson16.Lesson16;
1111
import com.codedifferently.lesson16.library.Library;
1212
import com.codedifferently.lesson16.library.LibraryGuest;
13-
import com.codedifferently.lesson16.library.Patron;
14-
import java.util.HashSet;
1513
import java.util.List;
16-
import java.util.Set;
1714
import java.util.UUID;
1815
import org.junit.jupiter.api.BeforeAll;
1916
import org.junit.jupiter.api.Test;
@@ -80,33 +77,19 @@ void testController_reportsBadRequestOnAddPatron() throws Exception {
8077
@Test
8178
void testController_addsPatron() throws Exception {
8279
String json =
83-
"""
84-
{
85-
"guests":{
86-
{
87-
"id": "ca4a7abd-95fa-43db-91c7-5d80e27d821a"
88-
"name": "John Book",
89-
"email": "[email protected]",
90-
"checkedOutPatrons": []
91-
}
92-
}
93-
""";
80+
"""
81+
{
82+
"patron":{
83+
"name": "John Book",
84+
"email": "[email protected]",
85+
}
86+
}
87+
""";
9488

9589
mockMvc
9690
.perform(post("/patrons").contentType(MediaType.APPLICATION_JSON).content(json))
9791
.andExpect(status().isOk())
98-
.andExpect(jsonPath("$.patron.id").value("ca4a7abd-95fa-43db-91c7-5d80e27d821a"));
99-
100-
Set<LibraryGuest> patrons = new HashSet<>();
101-
for (LibraryGuest guest : library.getInfo().getGuests()) {
102-
if (guest.getId() == UUID.fromString("ca4a7abd-95fa-43db-91c7-5d80e27d821a")) {
103-
patrons.add(guest);
104-
}
105-
}
106-
assertThat(patrons).hasSize(1);
107-
var patron = patrons.iterator().next();
108-
assertThat(patron).isInstanceOf(Patron.class);
109-
assertThat(patron.getName()).isEqualTo("John Book");
92+
.andExpect(jsonPath("$.patrons.name").value("John Book"));
11093
}
11194

11295
@Test

0 commit comments

Comments
 (0)