test_class.declarator: PATH_TO_RESOURCE = "/found"
test_class.modifier: private static final
test_class.original_string: private static final String PATH_TO_RESOURCE = "/found";
test_class.type: String
test_class.var_name: PATH_TO_RESOURCE
test_class.declarator: PATH_TO_MISSING_RESOURCE = "/notFound"
test_class.modifier: private static final
test_class.original_string: private static final String PATH_TO_MISSING_RESOURCE = "/notFound";
test_class.type: String
test_class.var_name: PATH_TO_MISSING_RESOURCE
test_class.declarator: TEST_PORT = 9090
test_class.modifier: private static final
test_class.original_string: private static final int TEST_PORT = 9090;
test_class.type: int
test_class.var_name: TEST_PORT
test_class.declarator: TEST_HOST = "localhost"
test_class.modifier: private static final
test_class.original_string: private static final String TEST_HOST = "localhost";
test_class.type: String
test_class.var_name: TEST_HOST
test_class.declarator: TEST_TIMEOUT = 1000
test_class.modifier: private static final
test_class.original_string: private static final int TEST_TIMEOUT = 1000;
test_class.type: int
test_class.var_name: TEST_TIMEOUT
test_class.declarator: SERVER_RESPONSE = "content"
test_class.modifier: private static final
test_class.original_string: private static final String SERVER_RESPONSE = "content";
test_class.type: String
test_class.var_name: SERVER_RESPONSE
test_class.declarator: server
test_class.modifier: private static
test_class.original_string: private static Server server;
test_class.type: Server
test_class.var_name: server
test_class.declarator: testCallback = s -> new String(s)
test_class.modifier: private
test_class.original_string: private ContentReceviedCallback<String> testCallback = s -> new String(s);
test_class.type: ContentReceviedCallback<String>
test_class.var_name: testCallback
test_class.declarator: testClient = new CachingHttpClient<>(testCallback)
test_class.modifier: private
test_class.original_string: private CachingHttpClient<String> testClient = new CachingHttpClient<>(testCallback);
test_class.type: CachingHttpClient<String>
test_class.var_name: testClient
test_class.file: custom-checks/checkstyle/src/test/java/org/openhab/tools/analysis/utils/CachingHttpClientTest.java
test_class.identifier: CachingHttpClientTest
test_case.body: @Test
      public void testFailureAndSuccess() throws Exception {
          URL url = getUniqueURL(PATH_TO_RESOURCE);
  
          // The server stops responding
          Mockito.doNothing().when(server.getHandler()).handle(any(), any(), any(), any());
  
          // First request throws exception, because a get request is sent
          try {
              testClient.get(url);
          } catch (IOException e) {
              assertThat(e, instanceOf(IOException.class));
              assertThat(e.getMessage(), equalTo("Unable to get " + url.toString()));
              assertThat(e.getCause(), instanceOf(FileNotFoundException.class));
          }
  
          mockHandler(server.getHandler());
  
          // Next requests do not throw exception
          assertNull(testClient.get(url));
          assertNull(testClient.get(url));
  
          verify(server.getHandler(), times(1)).handle(any(), any(), any(), any());
      }
test_case.class_method_signature: CachingHttpClientTest.testFailureAndSuccess()
test_case.full_signature: @Test public void testFailureAndSuccess()
test_case.identifier: testFailureAndSuccess
test_case.invocations: getUniqueURL handle when doNothing getHandler any any any any get assertThat instanceOf assertThat getMessage equalTo toString assertThat getCause instanceOf mockHandler getHandler assertNull get assertNull get handle verify getHandler times any any any any
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testFailureAndSuccess()
focal_class.declarator: RETRY_TIME = 10
focal_class.modifier: private static final
focal_class.original_string: private static final int RETRY_TIME = 10;
focal_class.type: int
focal_class.var_name: RETRY_TIME
focal_class.declarator: cache = CacheBuilder.newBuilder()
              .expireAfterWrite(RETRY_TIME, TimeUnit.MINUTES).build()
focal_class.modifier: private static
focal_class.original_string: private static Cache<URL, Optional<byte[]>> cache = CacheBuilder.newBuilder()
              .expireAfterWrite(RETRY_TIME, TimeUnit.MINUTES).build();
focal_class.type: Cache<URL, Optional<byte[]>>
focal_class.var_name: cache
focal_class.declarator: callback
focal_class.modifier: private
focal_class.original_string: private ContentReceviedCallback<T> callback;
focal_class.type: ContentReceviedCallback<T>
focal_class.var_name: callback
focal_class.file: custom-checks/checkstyle/src/main/java/org/openhab/tools/analysis/utils/CachingHttpClient.java
focal_class.identifier: CachingHttpClient
focal_class.class_method_signature: CachingHttpClient.CachingHttpClient(ContentReceviedCallback<T> callback)
focal_class.full_signature: public  CachingHttpClient(ContentReceviedCallback<T> callback)
focal_class.identifier: CachingHttpClient
focal_class.modifiers: public
focal_class.parameters: (ContentReceviedCallback<T> callback)
focal_class.signature:  CachingHttpClient(ContentReceviedCallback<T> callback)
focal_class.class_method_signature: CachingHttpClient.get(URL url)
focal_class.full_signature: public synchronized T get(URL url)
focal_class.identifier: get
focal_class.modifiers: public synchronized
focal_class.parameters: (URL url)
focal_class.return: T
focal_class.signature: T get(URL url)
focal_class.class_method_signature: CachingHttpClient.getContent(URL url)
focal_class.full_signature: private byte[] getContent(URL url)
focal_class.identifier: getContent
focal_class.modifiers: private
focal_class.parameters: (URL url)
focal_class.return: byte[]
focal_class.signature: byte[] getContent(URL url)
focal_method.body: public synchronized T get(URL url) throws IOException {
          if (url == null) {
              throw new IllegalArgumentException("URL must not be null");
          }
  
          Optional<byte[]> content = Optional.empty();
          try {
              content = cache.get(url, () -> Optional.of(getContent(url)));
          } catch (ExecutionException e) {
              cache.put(url, Optional.empty());
              throw new IOException("Unable to get " + url.toString(), e.getCause());
          }
          return content.isPresent() ? callback.transform(content.get()) : null;
      }
focal_method.class_method_signature: CachingHttpClient.get(URL url)
focal_method.full_signature: public synchronized T get(URL url)
focal_method.identifier: get
focal_method.invocations: empty get of getContent put empty toString getCause isPresent transform get
focal_method.modifiers: public synchronized
focal_method.parameters: (URL url)
focal_method.return: T
focal_method.signature: T get(URL url)