### Question:
RestConfigReader implements ConfigReader { @Override public InputStream read(final URI configUri) throws IOException { int numOfTries = 0; InputStream result = null; while (numOfTries <= retryPolicy.getMaxRetries()) { try { numOfTries++; result = getConfigurationStream(configUri); break; } catch (final IOException e) { if (numOfTries == retryPolicy.getMaxRetries()) { logger.error("Failed to load configurations from {}, number of attempts exceeded the maximum ({}).", configUri, retryPolicy.getMaxRetries(), e); throw e; } else { logger.warn("Failed to load configuration from {}, this is attempt {} of {}. The error is - {}.", configUri, numOfTries, retryPolicy.getMaxRetries(), e); retryPolicy.delay(); } } } return result; } RestConfigReader(final RetryPolicy retryPolicy, final HttpClient httpClient, final int connectionTimeout, final int socketTimeout); @Override InputStream read(final URI configUri); int getConnectionTimeout(); int getSocketTimeout(); RetryPolicy getRetryPolicy();  }### Answer:
@Test public void readSuccessfully() throws URISyntaxException, IOException { String configuration = "something to do"; URI uri = new URI("http: try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(configuration.getBytes())) { Mockito.when(httpEntityMock.getContent()).thenReturn(byteArrayInputStream); InputStream result = restConfigReader.read(uri); Assert.assertNotNull(result); Assert.assertEquals(configuration, IOUtils.toString(result)); } }
@Test() public void readFailAfterAllRetries() throws URISyntaxException, IOException { URI uri = new URI("http: RestConfigReader restConfigReaderSpy = Mockito.spy(new RestConfigReader(retryPolicy, HttpClients.createDefault(), 1, 1)); thrown.expect(IOException.class); restConfigReaderSpy.read(uri); }