Skip to content

Commit

Permalink
Merge pull request #91 from nastiausenko/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
egorsivenko authored Apr 24, 2024
2 parents 70b013b + cb3efbf commit f6b07af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ResponseEntity<Object> handleEmailAlreadyTakenException(
* @return {@link ResponseEntity} object with the corresponding status and error message
*/
@ExceptionHandler({NoSuchEmailFoundException.class,
NoUserFoundByEmailException.class, NoUserFoundByIdException.class})
NoUserFoundByEmailException.class, NoUserFoundByIdException.class, NoLinkFoundByShortLinkException.class})
public ResponseEntity<Object> handleNotFoundExceptions(
RuntimeException ex, HttpServletRequest request) {
ErrorResponse errorResponse = buildErrorResponse(HttpStatus.NOT_FOUND,
Expand Down Expand Up @@ -112,14 +112,6 @@ public ResponseEntity<Object> handleForbiddenException(
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(errorResponse);
}

@ExceptionHandler({NoLinkFoundByIdException.class, NoLinkFoundByShortLinkException.class})
public ResponseEntity<Object> handleNoLinkFoundByIdException(
RuntimeException ex, HttpServletRequest request) {
ErrorResponse errorResponse = buildErrorResponse(HttpStatus.NOT_FOUND,
ex.getMessage(), request.getRequestURI());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}

@ExceptionHandler({DeletedLinkException.class, InactiveLinkException.class})
public ResponseEntity<Object> handleDeletedAndInactiveLinkException(
RuntimeException ex, HttpServletRequest request) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ void getLongLinkFromShortLinkInactiveTest() throws JsonProcessingException {
.isInstanceOf(InactiveLinkException.class);
}

/**
* Test case for the {@link LinkService#getLongLinkFromShortLink(String)} method when link expiration time
* has passed.
*/
@Test
void getLongLinkFromShortLinkExpiredTest() throws JsonProcessingException {
link.setExpirationTime(LocalDateTime.now().minusDays(1));
when(jedisPool.getResource()).thenReturn(jedis);
when(jedis.exists(anyString())).thenReturn(true);
when(jedis.get(anyString())).thenReturn("{}");
when(mapper.readValue(anyString(), eq(Link.class))).thenReturn(link);

assertThatThrownBy(() -> linkService.getLongLinkFromShortLink(link.getShortLink()))
.isInstanceOf(InactiveLinkException.class);
}

/**
* Test case for the {@link LinkService#findByShortLink(String)} method.
*/
Expand Down

0 comments on commit f6b07af

Please sign in to comment.