@Test public void test_download_docker_machine() throws IOException { HttpURLConnection connection = mock(HttpURLConnection.class); URL url = mockUrl(connection); String content = "{\"id\":\"1\", \"name\":\"v0.5.5\", \"tag_name\":\"v0.5.5\"}"; when(connection.getInputStream()).thenReturn(new ByteArrayInputStream(content.getBytes())); assertThat(GitHubUtil.consumeHttp(url).getTagName(), is("v0.5.5")); }
public static LatestRepository consumeHttp(URL url) { try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); ObjectMapper mapper = new ObjectMapper(); LatestRepository latestRepository = mapper.readValue(connection.getInputStream(), LatestRepository.class); return latestRepository; } catch (IOException e) { log.log(Level.WARNING, e.getMessage()); } return null; }
GitHubUtil { public static LatestRepository consumeHttp(URL url) { try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); ObjectMapper mapper = new ObjectMapper(); LatestRepository latestRepository = mapper.readValue(connection.getInputStream(), LatestRepository.class); return latestRepository; } catch (IOException e) { log.log(Level.WARNING, e.getMessage()); } return null; } }
GitHubUtil { public static LatestRepository consumeHttp(URL url) { try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); ObjectMapper mapper = new ObjectMapper(); LatestRepository latestRepository = mapper.readValue(connection.getInputStream(), LatestRepository.class); return latestRepository; } catch (IOException e) { log.log(Level.WARNING, e.getMessage()); } return null; }  }
GitHubUtil { public static LatestRepository consumeHttp(URL url) { try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); ObjectMapper mapper = new ObjectMapper(); LatestRepository latestRepository = mapper.readValue(connection.getInputStream(), LatestRepository.class); return latestRepository; } catch (IOException e) { log.log(Level.WARNING, e.getMessage()); } return null; }  static String getDockerMachineLatestVersion(); static LatestRepository consumeHttp(URL url); }
GitHubUtil { public static LatestRepository consumeHttp(URL url) { try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); ObjectMapper mapper = new ObjectMapper(); LatestRepository latestRepository = mapper.readValue(connection.getInputStream(), LatestRepository.class); return latestRepository; } catch (IOException e) { log.log(Level.WARNING, e.getMessage()); } return null; }  static String getDockerMachineLatestVersion(); static LatestRepository consumeHttp(URL url);  }