RemoteServiceDescriptor { public ServiceDescriptor getServiceDescriptor() throws IOException, ServerException { if (serviceDescriptor == null) { synchronized (this) { if (serviceDescriptor == null) { try { serviceDescriptor = requestFactory .fromUrl(baseUrl) .useOptionsMethod() .request() .as(getServiceDescriptorClass(), null); } catch (NotFoundException | ConflictException | UnauthorizedException | BadRequestException | ForbiddenException e) { throw new ServerException(e.getServiceError()); } } } } return serviceDescriptor; } RemoteServiceDescriptor(String baseUrl, HttpJsonRequestFactory requestFactory); String getBaseUrl(); List<Link> getLinks(); Link getLink(String rel); ServiceDescriptor getServiceDescriptor(); boolean isAvailable();  }
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "test error") public void shouldThrowServerExceptionIfServiceNotFound() throws Exception { doReturn(request).when(requestFactory).fromUrl(anyString()); when(request.request()).thenThrow(new NotFoundException("test error")); remoteServiceDescriptor = new RemoteServiceDescriptor(serverUrl + "/non/existing/path", requestFactory); remoteServiceDescriptor.getServiceDescriptor(); }