VersionComponentImpl implements VersionComponent { @Override @SuppressWarnings("unchecked") public CompletableFuture<String> latestVersion() { return Rest.connectHttps("service.speedment.com") .get(format("version/%s/latest", info.getRepository())) .thenApplyAsync(res -> { if (res.success()) { return res.decodeJson() .map(m -> (Map<String, String>) m) .map(m -> m.get("tag")) .orElseThrow(() -> new SpeedmentToolException( "Could not establish the latest version." )); } else { throw new SpeedmentToolException( "Received an error '" + res.getText() + "' from the GitHub API." ); } }); } VersionComponentImpl(InfoComponent info); @Override @SuppressWarnings("unchecked") CompletableFuture<String> latestVersion();  }
@Test void testLatestVersion() { assertDoesNotThrow(() -> { LOGGER.info("Determining the latest version of Speedment."); final Speedment speedment = ApplicationBuilders.empty() .withBundle(GeneratorBundle.class) .withBundle(ToolBundle.class) .withSkipCheckDatabaseConnectivity() .withSkipValidateRuntimeConfig() .withInjectorProxy(new TestInjectorProxy()) .build(); final VersionComponent version = speedment.getOrThrow(VersionComponent.class); try { final String latest = version.latestVersion().get(2, TimeUnit.SECONDS); LOGGER.info("The latest released version of Speedment is " + latest + "."); } catch (final ExecutionException | InterruptedException ex) { if (hasCause(ex, UnknownHostException.class)) { LOGGER.warn(ex, "Not connected to the Internet?"); } else { LOGGER.error(ex); } } catch (final TimeoutException ex) { LOGGER.error(ex, "Connection timed out before a version could be established."); } }); }