Skip to content
Snippets Groups Projects
Commit 57aef9f5 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2966 OZG-3171 catch IllegalArgumentException

parent 1fcc86b4
Branches
Tags
No related merge requests found
......@@ -86,6 +86,8 @@ public class UserRemoteService {
return null;
}
throw new ServiceUnavailableException(MessageCode.USER_MANAGER_SERVICE_UNAVAILABLE, e);
} catch (IllegalArgumentException e) {
throw new ServiceUnavailableException(MessageCode.USER_MANAGER_SERVICE_UNAVAILABLE, e);
}
}
......
......@@ -200,17 +200,26 @@ class UserRemoteServiceTest {
@Nested
class TestOnErrorResponse {
private final HttpClientErrorException serviceUnavailableException = new HttpClientErrorException(HttpStatus.SERVICE_UNAVAILABLE,
private final HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.SERVICE_UNAVAILABLE,
"Test error");
private final IllegalArgumentException illegalArgumentException = new IllegalArgumentException();
private final HttpClientErrorException notFoundException = new HttpClientErrorException(HttpStatus.NOT_FOUND, "Test error");
@Test
void shouldThrowServiceUnavailablExceptionOnException() {
when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), any(), eq(Object.class))).thenThrow(serviceUnavailableException);
when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), any(), eq(Object.class))).thenThrow(httpClientErrorException);
assertThatThrownBy(() -> service.getUser(UserProfileTestFactory.ID)).isInstanceOf(ServiceUnavailableException.class)
.hasCause(serviceUnavailableException);
.hasCause(httpClientErrorException);
}
@Test
void shouldThrowServiceUnavailablExceptionOnIlleglaArgumentException() {
when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), any(), eq(Object.class))).thenThrow(illegalArgumentException);
assertThatThrownBy(() -> service.getUser(UserProfileTestFactory.ID)).isInstanceOf(ServiceUnavailableException.class)
.hasCause(illegalArgumentException);
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment