### Question:
ConfigRetriever { public Map<String, ComprehendConfiguration> retrieveStoredConfig() { Response esConfigResponse = esClient.performRequest(HttpGet.METHOD_NAME, String.format("%s%s", Constants.CONFIG_PATH, "/_source")); if (esConfigResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { return Collections.emptyMap(); } String retrievedConfig = HTTPTransformer.transformHttpEntityToString(esConfigResponse.getEntity()); PreprocessingConfigRequest retrievedConfigRequest = configSerializer.deserialize(retrievedConfig); return ConfigSerializer.transformConfigRequestToConfigMap(retrievedConfigRequest); }  Map<String, ComprehendConfiguration> retrieveStoredConfig();  }### Answer:
@Test public void succeedRetrieveStoredConfig() { when(mockStatusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); when(HTTPTransformer.transformHttpEntityToString(any())).thenReturn(TestConstants.CONFIG); when(mockConfigSerializer.deserialize(TestConstants.CONFIG)).thenReturn(TestConstants.getConfigRequest()); when(ConfigSerializer.transformConfigRequestToConfigMap(any())).thenReturn(TestConstants.getConfigMap()); Map<String, ComprehendConfiguration> configMap = test.retrieveStoredConfig(); assertEquals(TestConstants.getConfigMap(), configMap); }
@Test public void failedToRetrieveStoredConfig() { when(mockStatusLine.getStatusCode()).thenReturn(HttpStatus.SC_NOT_FOUND); Map<String, ComprehendConfiguration> configMap = test.retrieveStoredConfig(); verifyZeroInteractions(mockConfigSerializer); assertEquals(Collections.EMPTY_MAP, configMap); }
@Test(expected = InternalErrorException.class) public void failedToPerformRequest() { ElasticsearchClient mockBadESClient = mock(ElasticsearchClient.class); when(mockBadESClient.performRequest(anyString(), anyString())).thenThrow(new InternalErrorException("")); test = new ConfigRetriever(mockConfigSerializer, mockBadESClient); test.retrieveStoredConfig(); }
@Test(expected = InvalidRequestException.class) public void failedToDeserializeRetrievedConfig() { when(mockStatusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); when(HTTPTransformer.transformHttpEntityToString(any())).thenReturn(TestConstants.CONFIG); when(mockConfigSerializer.deserialize(TestConstants.CONFIG)) .thenThrow(new InvalidRequestException(TestConstants.DUMMY_ERROR_MESSAGE)); test.retrieveStoredConfig(); }