|
10 | 10 | import com.codedifferently.lesson16.Lesson16;
|
11 | 11 | import com.codedifferently.lesson16.library.Library;
|
12 | 12 | import com.codedifferently.lesson16.library.LibraryGuest;
|
13 |
| -import com.codedifferently.lesson16.library.Patron; |
14 |
| -import java.util.HashSet; |
15 | 13 | import java.util.List;
|
16 |
| -import java.util.Set; |
17 | 14 | import java.util.UUID;
|
18 | 15 | import org.junit.jupiter.api.BeforeAll;
|
19 | 16 | import org.junit.jupiter.api.Test;
|
@@ -80,33 +77,19 @@ void testController_reportsBadRequestOnAddPatron() throws Exception {
|
80 | 77 | @Test
|
81 | 78 | void testController_addsPatron() throws Exception {
|
82 | 79 | String json =
|
83 |
| - """ |
84 |
| - { |
85 |
| - "guests":{ |
86 |
| - { |
87 |
| - "id": "ca4a7abd-95fa-43db-91c7-5d80e27d821a" |
88 |
| - "name": "John Book", |
89 |
| - |
90 |
| - "checkedOutPatrons": [] |
91 |
| - } |
92 |
| - } |
93 |
| - """; |
| 80 | + """ |
| 81 | + { |
| 82 | + "patron":{ |
| 83 | + "name": "John Book", |
| 84 | + |
| 85 | + } |
| 86 | + } |
| 87 | + """; |
94 | 88 |
|
95 | 89 | mockMvc
|
96 | 90 | .perform(post("/patrons").contentType(MediaType.APPLICATION_JSON).content(json))
|
97 | 91 | .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")); |
110 | 93 | }
|
111 | 94 |
|
112 | 95 | @Test
|
|
0 commit comments