### Question:
SaveSpaceUsageToFile implements SpaceUsagePersistence { @Override public OptionalLong load() { try (Scanner sc = new Scanner(file, UTF_8.name())) { if (!sc.hasNextLong()) { LOG.info("Cached usage info in {} has no value", file); return OptionalLong.empty(); } long cachedValue = sc.nextLong(); if (!sc.hasNextLong()) { LOG.info("Cached usage info in {} has no time", file); return OptionalLong.empty(); } Instant time = Instant.ofEpochMilli(sc.nextLong()); if (isExpired(time)) { LOG.info("Cached usage info in {} is expired: {} ", file, time); return OptionalLong.empty(); } LOG.info("Cached usage info found in {}: {} at {}", file, cachedValue, time); return OptionalLong.of(cachedValue); } catch (FileNotFoundException e) { LOG.info("Cached usage info file {} not found", file); return OptionalLong.empty(); } } SaveSpaceUsageToFile(File file, Duration expiry); @Override OptionalLong load(); @Override void save(SpaceUsageSource source);  }### Answer:
@Test public void doesNotLoadIfTimeMissing() throws IOException { saveToFile(Long.toString(VALID_USAGE_SOURCE.getUsedSpace())); SpaceUsagePersistence subject = new SaveSpaceUsageToFile(file, LONG_EXPIRY); OptionalLong savedValue = subject.load(); assertFalse(savedValue.isPresent()); }
@Test public void doesNotLoadIfFileMissing() { SpaceUsagePersistence subject = new SaveSpaceUsageToFile(file, LONG_EXPIRY); OptionalLong savedValue = subject.load(); assertFalse(file.exists()); assertFalse(savedValue.isPresent()); }
@Test public void doesNotLoadGarbage() throws IOException { saveToFile("garbage 456"); SpaceUsagePersistence subject = new SaveSpaceUsageToFile(file, LONG_EXPIRY); OptionalLong savedValue = subject.load(); assertFalse(savedValue.isPresent()); }