GitHubLastUpdateCache { public <T> void store(T asset, String uniqueKey, ZonedDateTime dateTime) { final File cachedFilePath = createCachedFilePath(uniqueKey).toFile(); final JsonObject jsonObject = combineAsJson(asset, dateTime); try (FileOutputStream fileOutputStream = new FileOutputStream(cachedFilePath, false)) { fileOutputStream.write(jsonObject.toString().getBytes()); } catch (IOException e) { throw new RuntimeException("Unable to store " + jsonObject + "%n as [" + cachedFilePath + "]", e); } } GitHubLastUpdateCache(final Path cacheDirectory);  GitHubLastUpdateCache(final File cacheDirectory);  GitHubLastUpdateCache(); ZonedDateTime lastModificationOf(String uniqueKey); T load(String uniqueKey, Class<T> type); boolean cacheFileExists(String uniqueKey); void store(T asset, String uniqueKey, ZonedDateTime dateTime);  }
@Test public void should_create_release_cache_folder() throws Exception { final File customCacheFolder = new File(tmpFolder, "custom-cache-folder"); final ExternalBinary externalBinary = new ExternalBinary("1.0.0.Final", "https: final String releasesId = "4968399"; gitHubLastUpdateCache = new GitHubLastUpdateCache(customCacheFolder); gitHubLastUpdateCache.store(externalBinary, releasesId, ZonedDateTime.now()); final SoftAssertions softly = new SoftAssertions(); softly.assertThat(customCacheFolder).exists().isDirectory(); softly.assertThat(new File(customCacheFolder, "gh.cache.4968399.json")).isFile().has(new Condition<File>() { @Override public boolean matches(File value) { return value.length() > 0; } }); softly.assertAll(); }
@Test public void should_store_external_binary() throws Exception { final ExternalBinary externalBinary = new ExternalBinary("1.0.0.Final", "https: final String releasesId = "4968399"; gitHubLastUpdateCache.store(externalBinary, releasesId, ZonedDateTime.now()); assertThat(tmpFolder.listFiles()).containsOnly(new File(tmpFolder.getAbsolutePath() + "/gh.cache.4968399.json")); }