Source:
<code>public void testGetContentForHttp429And200() throws Exception { String validResult = "this is valid result"; HttpContentRetriever service = prepareValidService(); CloseableHttpResponse getRateLimitedContentHttpResponse = mock(CloseableHttpResponse.class); <START> { StatusLine getContentStatusLine = mock(StatusLine.class); when(getRateLimitedContentHttpResponse.getStatusLine()).thenReturn(getContentStatusLine); when(getContentStatusLine.getStatusCode()).thenReturn(429); HttpEntity getContentHttpEntity = mock(HttpEntity.class); when(getRateLimitedContentHttpResponse.getEntity()).thenReturn(getContentHttpEntity); when(getContentHttpEntity.getContent()).thenReturn(new ByteArrayInputStream("".getBytes())); } <END> CloseableHttpResponse getValidContentHttpResponse = mock(CloseableHttpResponse.class); { StatusLine getMovedContentStatusLine = mock(StatusLine.class); HttpEntity getMovedContentHttpEntity = mock(HttpEntity.class); when(getValidContentHttpResponse.getStatusLine()).thenReturn(getMovedContentStatusLine); when(getMovedContentStatusLine.getStatusCode()).thenReturn(200); when(getValidContentHttpResponse.getEntity()).thenReturn(getMovedContentHttpEntity); when(getMovedContentHttpEntity.getContent()).thenReturn(new ByteArrayInputStream(validResult.getBytes())); } when(httpClient.execute(any(HttpGet.class))).thenReturn(getRateLimitedContentHttpResponse, getValidContentHttpResponse); ContentRetrieverResponse response = service.retrieveUrlContent("someUrl"); assertNotNull(response); assertNull(response.getException()); assertEquals(validResult, response.getContent()); }</code><technical_language>I braces is necessary</technical_language>

Target:
public void testGetContentForHttp429And200() throws Exception { String validResult = "this is valid result"; HttpContentRetriever service = prepareValidService(); CloseableHttpResponse getRateLimitedContentHttpResponse = mock(CloseableHttpResponse.class); StatusLine getContentStatusLine = mock(StatusLine.class); when(getRateLimitedContentHttpResponse.getStatusLine()).thenReturn(getContentStatusLine); when(getContentStatusLine.getStatusCode()).thenReturn(429); HttpEntity getContentHttpEntity = mock(HttpEntity.class); when(getRateLimitedContentHttpResponse.getEntity()).thenReturn(getContentHttpEntity); when(getContentHttpEntity.getContent()).thenReturn(new ByteArrayInputStream("".getBytes())); CloseableHttpResponse getValidContentHttpResponse = mock(CloseableHttpResponse.class); StatusLine getMovedContentStatusLine = mock(StatusLine.class); HttpEntity getMovedContentHttpEntity = mock(HttpEntity.class); when(getValidContentHttpResponse.getStatusLine()).thenReturn(getMovedContentStatusLine); when(getMovedContentStatusLine.getStatusCode()).thenReturn(200); when(getValidContentHttpResponse.getEntity()).thenReturn(getMovedContentHttpEntity); when(getMovedContentHttpEntity.getContent()).thenReturn(new ByteArrayInputStream(validResult.getBytes())); when(httpClient.execute(any(HttpGet.class))).thenReturn(getRateLimitedContentHttpResponse, getValidContentHttpResponse); ContentRetrieverResponse response = service.retrieveUrlContent("someUrl"); assertNotNull(response); assertNull(response.getException()); assertEquals(validResult, response.getContent()); }