Skip to content

Commit 532d7ba

Browse files
committed
Patch10_08
1 parent 902161a commit 532d7ba

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/main/java/ru/javawebinar/topjava/util/exception/NotFoundException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package 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
711
public class NotFoundException extends RuntimeException {
812
public NotFoundException(String message) {
913
super(message);

src/test/java/ru/javawebinar/topjava/web/meal/UserMealRestControllerTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

src/test/java/ru/javawebinar/topjava/web/user/AdminRestControllerTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)