### Question:
CachedApiDocService { public String getApiDocForService(final String serviceId, final String apiVersion) { String apiDoc = CachedApiDocService.serviceApiDocs.get(new ApiDocCacheKey(serviceId, apiVersion)); try { ApiDocInfo apiDocInfo = apiDocRetrievalService.retrieveApiDoc(serviceId, apiVersion); if (apiDocInfo != null && apiDocInfo.getApiDocContent() != null) { apiDoc = transformApiDocService.transformApiDoc(serviceId, apiDocInfo); CachedApiDocService.serviceApiDocs.put(new ApiDocCacheKey(serviceId, apiVersion), apiDoc); } if (apiDoc == null) { throw new ApiDocNotFoundException("No API Documentation was retrieved for the service " + serviceId + "."); } } catch (Exception e) { if (apiDoc == null) { throw new ApiDocNotFoundException("No API Documentation was retrieved for the service " + serviceId + "."); } } return apiDoc; } @Autowired  CachedApiDocService(APIDocRetrievalService apiDocRetrievalService, TransformApiDocService transformApiDocService); String getApiDocForService(final String serviceId, final String apiVersion); void updateApiDocForService(final String serviceId, final String apiVersion, final String apiDoc); void resetCache();  }### Answer:
@Test public void givenValidApiDoc_whenRetrieving_thenReturnIt() { String serviceId = "Service"; String version = "v1"; String expectedApiDoc = "This is some api doc"; ApiDocInfo apiDocInfo = new ApiDocInfo(null, expectedApiDoc, null); when(apiDocRetrievalService.retrieveApiDoc(serviceId, version)) .thenReturn(apiDocInfo); when(transformApiDocService.transformApiDoc(serviceId, apiDocInfo)) .thenReturn(expectedApiDoc); String apiDoc = cachedApiDocService.getApiDocForService(serviceId, version); Assert.assertNotNull(apiDoc); Assert.assertEquals(expectedApiDoc, apiDoc); }
@Test public void givenInvalidApiDoc_whenRetrieving_thenThrowException() { String serviceId = "Service"; String version = "v1"; Exception exception = assertThrows(ApiDocNotFoundException.class, () -> cachedApiDocService.getApiDocForService(serviceId, version), "Expected exception is not ApiDocNotFoundException"); assertEquals("No API Documentation was retrieved for the service Service.", exception.getMessage()); }