Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit b44bc08

Browse files
dev/codeforces/test Написал интеграционные тесты для TeamController
1 parent f0c092c commit b44bc08

File tree

2 files changed

+411
-1
lines changed

2 files changed

+411
-1
lines changed
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
11
package com.cf.cfteam.advicers.codeforces;
22

3-
import com.cf.cfteam.exceptions.codeforces.GroupNotFoundException;
3+
import com.cf.cfteam.exceptions.codeforces.*;
44
import com.cf.cfteam.utils.ErrorResponseBuilder;
55
import org.springframework.http.HttpStatus;
66
import org.springframework.http.ResponseEntity;
77
import org.springframework.web.bind.annotation.ControllerAdvice;
88
import org.springframework.web.bind.annotation.ExceptionHandler;
99

10+
import java.util.HashMap;
1011
import java.util.Map;
1112

1213
@ControllerAdvice
1314
public class CodeforcesExceptionHandler {
1415
private static final String ID = "id";
16+
private static final String LOGIN = "login";
17+
private static final String TEAM_ID = "teamId";
18+
private static final String PLAYER_ID = "playerId";
1519

1620
@ExceptionHandler(GroupNotFoundException.class)
1721
public ResponseEntity<Object> handleUserNotFoundException(GroupNotFoundException ex) {
1822
return ErrorResponseBuilder.buildErrorResponse(ex.getMessage(), HttpStatus.NOT_FOUND, Map.of(ID, ex.getId()));
1923
}
2024

25+
@ExceptionHandler(TeamNotFoundException.class)
26+
public ResponseEntity<Object> handleTeamNotFoundException(TeamNotFoundException ex) {
27+
return ErrorResponseBuilder.buildErrorResponse(ex.getMessage(), HttpStatus.NOT_FOUND, Map.of(ID, ex.getId()));
28+
}
29+
30+
@ExceptionHandler(PlayerNotFoundException.class)
31+
public ResponseEntity<Object> handlePayerNotFoundException(PlayerNotFoundException ex) {
32+
return ErrorResponseBuilder.buildErrorResponse(ex.getMessage(), HttpStatus.NOT_FOUND, Map.of(ID, ex.getId()));
33+
}
34+
35+
@ExceptionHandler(PlayerAlreadyInTeamException.class)
36+
public ResponseEntity<Object> handlePlayerAlreadyInTeamException(PlayerAlreadyInTeamException ex) {
37+
return ErrorResponseBuilder.buildErrorResponse(ex.getMessage(), HttpStatus.NOT_FOUND, Map.of(LOGIN, ex.getLogin()));
38+
}
39+
40+
@ExceptionHandler(PlayerNotFromTeamException.class)
41+
public ResponseEntity<Object> handlePlayerNotFromTeamException(PlayerNotFromTeamException ex) {
42+
Map<String, Object> details = new HashMap<>();
43+
if (ex.getPlayerId() != null) {
44+
details.put(PLAYER_ID, ex.getPlayerId());
45+
}
46+
if (ex.getTeamId() != null) {
47+
details.put(TEAM_ID, ex.getTeamId());
48+
}
49+
50+
return ErrorResponseBuilder.buildErrorResponse(
51+
ex.getMessage(),
52+
HttpStatus.NOT_FOUND,
53+
details
54+
);
55+
}
2156
}

0 commit comments

Comments
 (0)