|
@@ -22,9 +22,7 @@ import java.util.Optional;
|
22
|
22
|
|
23
|
23
|
import static com.example.bakerylab.JsonUtil.asJsonString;
|
24
|
24
|
import static org.mockito.BDDMockito.given;
|
25
|
|
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
26
|
|
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
27
|
|
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
|
25
|
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
28
|
26
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
29
|
27
|
|
30
|
28
|
|
|
@@ -55,6 +53,7 @@ public class BakerControllerTest {
|
55
|
53
|
.build();
|
56
|
54
|
|
57
|
55
|
froilan = new Baker("Froilan", "Master Baker", "Croissants");
|
|
56
|
+ froilan.setId(1L);
|
58
|
57
|
}
|
59
|
58
|
|
60
|
59
|
// ================= Create Baker ================= //
|
|
@@ -157,14 +156,25 @@ public class BakerControllerTest {
|
157
|
156
|
|
158
|
157
|
// ================= Delete Baker ================= //
|
159
|
158
|
|
160
|
|
-
|
161
|
159
|
@Test
|
162
|
|
- public void deleteBakerSuccess() {
|
|
160
|
+ public void deleteBakerSuccess() throws Exception {
|
|
161
|
+
|
|
162
|
+ given(bakerRepository.findById(froilan.getId()))
|
|
163
|
+ .willReturn(Optional.ofNullable(froilan));
|
163
|
164
|
|
|
165
|
+ mvc.perform(delete("/bakers/{id}", froilan.getId())
|
|
166
|
+ .accept(MediaType.APPLICATION_JSON))
|
|
167
|
+ .andExpect(status().isOk());
|
164
|
168
|
}
|
165
|
169
|
|
166
|
170
|
@Test
|
167
|
|
- public void deleteBakerFail() {
|
|
171
|
+ public void deleteBakerFail() throws Exception {
|
168
|
172
|
|
|
173
|
+ given(bakerRepository.findById(froilan.getId()))
|
|
174
|
+ .willReturn(null);
|
|
175
|
+
|
|
176
|
+ mvc.perform(delete("bakers/{id}", froilan.getId())
|
|
177
|
+ .accept(MediaType.APPLICATION_JSON))
|
|
178
|
+ .andExpect(status().isNotFound());
|
169
|
179
|
}
|
170
|
180
|
}
|