### Question:
StreamService { public void restoreSnapshot(Stream stream, int snapshotNr) { TreeMap<Integer, Snapshot> snapshots = getSnapshots(stream); Snapshot snapshot = snapshots.get(snapshotNr); if (snapshot == null) { throw new DisplayException("Cannot restore snapshot. Stream " + stream.name + " does not contain snapshot number " + snapshotNr); } restoreSnapshot(snapshot); }  Stream readStream(StreamRepository repository, String name); Stream tryReadStream(StreamRepository repository, String name); Stream createStream(StreamRepository streamRepository, String name); void writeVersionHistory(Stream stream); Set<String> getStreamNames(StreamRepository repository); void deleteStream(Path repoLocation, String name); void deleteStream(StreamRepository repo, String name); void deleteStream(Stream stream); void deleteStreams(StreamRepository repository); TreeMap<Integer, Snapshot> getSnapshots(Stream stream); Snapshot takeSnapshot(Stream stream); void restoreLatestSnapshot(Stream stream); void restoreSnapshot(Stream stream, int snapshotNr); void restoreSnapshot(Snapshot snapshot); void deleteSnapshot(Snapshot snapshot); void clearReceiveTempDir(Stream stream); void takeSnapshotIfRequired(Stream stream, Instant now); void pruneSnapshots(Stream stream);  }### Answer:
@Test public void testRestoreSnapshot() throws Exception { Stream stream = service.createStream(repository, "test"); Path testFile = repository.getWorkingDirectory(stream).resolve( "test.txt"); Files.copy(new ByteArrayInputStream("Hello".getBytes("UTF-8")), testFile); Snapshot snapshot = service.takeSnapshot(stream); assertTrue(Files.exists(testFile)); Files.delete(testFile); assertFalse(Files.exists(testFile)); service.restoreSnapshot(snapshot); assertTrue(Files.exists(testFile)); Files.delete(testFile); VersionHistoryEntry lastEntry = service.readStream(repository, "test").versionHistory .getLastEntry(); assertThat(lastEntry, instanceOf(RestoreVersionHistoryEntry.class)); assertThat(((RestoreVersionHistoryEntry) lastEntry).restoredSnapshotNr, is(snapshot.nr)); }