File tree Expand file tree Collapse file tree
main/java/ru/javawebinar/topjava/util/exception
test/java/ru/javawebinar/topjava/web Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package ru .javawebinar .topjava .util .exception ;
22
3+ import org .springframework .http .HttpStatus ;
4+ import org .springframework .web .bind .annotation .ResponseStatus ;
5+
36/**
47 * User: gkislin
58 * Date: 19.08.2014
69 */
10+ @ ResponseStatus (value = HttpStatus .NOT_FOUND , reason = "No data found" ) // 404
711public class NotFoundException extends RuntimeException {
812 public NotFoundException (String message ) {
913 super (message );
Original file line number Diff line number Diff line change @@ -46,6 +46,21 @@ public void testGetUnauth() throws Exception {
4646 .andExpect (status ().isUnauthorized ());
4747 }
4848
49+ @ Test
50+ public void testGetNotFound () throws Exception {
51+ mockMvc .perform (get (REST_URL + ADMIN_MEAL_ID )
52+ .with (userHttpBasic (USER )))
53+ .andExpect (status ().isNotFound ());
54+ }
55+
56+ @ Test
57+ public void testDeleteNotFound () throws Exception {
58+ mockMvc .perform (delete (REST_URL + ADMIN_MEAL_ID ).contentType (MediaType .APPLICATION_JSON )
59+ .with (userHttpBasic (USER )))
60+ .andDo (print ())
61+ .andExpect (status ().isNotFound ());
62+ }
63+
4964 @ Test
5065 public void testDelete () throws Exception {
5166 mockMvc .perform (delete (REST_URL + MEAL1_ID ).contentType (MediaType .APPLICATION_JSON )
Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ public void testGet() throws Exception {
3333 .andExpect (MATCHER .contentMatcher (ADMIN ));
3434 }
3535
36+ @ Test
37+ public void testGetNotFound () throws Exception {
38+ mockMvc .perform (get (REST_URL + 1 )
39+ .with (TestUtil .userHttpBasic (ADMIN )))
40+ .andExpect (status ().isNotFound ())
41+ .andDo (print ());
42+ }
43+
3644 @ Test
3745 public void testGetByEmail () throws Exception {
3846 mockMvc .perform (get (REST_URL + "by?email=" + ADMIN .getEmail ())
@@ -51,6 +59,14 @@ public void testDelete() throws Exception {
5159 MATCHER .assertCollectionEquals (Collections .singletonList (ADMIN ), userService .getAll ());
5260 }
5361
62+ @ Test
63+ public void testDeleteNotFound () throws Exception {
64+ mockMvc .perform (delete (REST_URL + 1 )
65+ .with (TestUtil .userHttpBasic (ADMIN )))
66+ .andExpect (status ().isNotFound ())
67+ .andDo (print ());
68+ }
69+
5470 @ Test
5571 public void testGetUnauth () throws Exception {
5672 mockMvc .perform (get (REST_URL ).contentType (MediaType .APPLICATION_JSON )
You can’t perform that action at this time.
0 commit comments