### Question:
ApiDocReader { public String load(String location) { if (location == null || location.isEmpty()) { throw new ApiDocReaderException("API doc location can't be null or empty"); } String openAPIJsonContent = getOpenAPIJsonContent(location.trim()); boolean isValidJson = isValidOpenApi3Content(openAPIJsonContent); if (!isValidJson) { log.debug("Could not convert response body to an OpenAPI object"); throw new ApiDocReaderException("OpenAPI content is not valid"); } return openAPIJsonContent; }  String load(String location);  }### Answer:
@Test void givenFileLocationAsANull_whenLoadIsCalled_thenThrowApiDocReaderException() { Exception exception = assertThrows(ApiDocReaderException.class, () -> apiDocReader.load(null), "Expected exception is not ApiDocReaderException"); assertEquals("API doc location can't be null or empty", exception.getMessage()); }
@Test void givenEmptyFileLocation_whenLoadIsCalled_thenThrowApiDocReaderException() { Exception exception = assertThrows(ApiDocReaderException.class, () -> apiDocReader.load(""), "Expected exception is not ApiDocReaderException"); assertEquals("API doc location can't be null or empty", exception.getMessage()); }
@Test void givenFileLocation_whenFileIsNotExist_thenThrowApiDocReaderException() { ApiDocReader apiDocReader = new ApiDocReader(); Exception exception = assertThrows(ApiDocReaderException.class, () -> apiDocReader.load("invalid-path.json"), "Expected exception is not ApiDocReaderException"); assertEquals("OpenAPI file does not exist: invalid-path.json", exception.getMessage()); }
@Test void givenFileLocationWithInvalidJsonContent_whenLoadIsCalled_thenThrowApiDocReaderException() { Exception exception = assertThrows(ApiDocReaderException.class, () -> apiDocReader.load("api-doc-invalid-content.json"), "Expected exception is not ApiDocReaderException"); assertEquals("OpenAPI content is not valid", exception.getMessage()); }
@Test void givenFileLocationWithValidJsonContent_whenLoadIsCalled_thenOpenApiShouldMatchWithJsonContent() throws IOException { String actualOpenApi = apiDocReader.load("api-doc.json"); String expectedOpenApi = JsonReaderUtil.getJsonStringFromResource("api-doc.json"); assertNotNull(actualOpenApi, "Open api object is null"); assertEquals(expectedOpenApi, actualOpenApi, "Open api object is not equal with expected"); }
@Test void givenFileLocationNameWithSpaces_whenFileExists_thenOpenApiShouldMatchWithJsonContent() throws IOException { String actualOpenApi = apiDocReader.load(" api-doc.json "); String expectedOpenApi = JsonReaderUtil.getJsonStringFromResource("api-doc.json"); assertNotNull(actualOpenApi, "Open api object is null"); assertEquals(expectedOpenApi, actualOpenApi, "Open api object is not equal with expected"); }