VirtualDevicesTask implements AsyncSupplier<Collection<VirtualDevice>> { @Nullable @VisibleForTesting Snapshot getSnapshot(@NotNull Path snapshotDirectory) { Path snapshotProtocolBuffer = snapshotDirectory.resolve("snapshot.pb"); Path snapshotDirectoryName = snapshotDirectory.getFileName(); if (!Files.exists(snapshotProtocolBuffer)) { return new Snapshot(snapshotDirectoryName, myFileSystem); } try (InputStream in = Files.newInputStream(snapshotProtocolBuffer)) { return getSnapshot(SnapshotOuterClass.Snapshot.parseFrom(in), snapshotDirectoryName); } catch (IOException exception) { Logger.getInstance(VirtualDevicesTask.class).warn(snapshotDirectory.toString(), exception); return null; } } VirtualDevicesTask(boolean selectDeviceSnapshotComboBoxSnapshotsEnabled,
                     @NotNull FileSystem fileSystem,
                     @Nullable LaunchCompatibilityChecker checker); @NotNull @Override ListenableFuture<Collection<VirtualDevice>> get();  }
@Test public void getSnapshotSnapshotProtocolBufferDoesntExist() { Path directory = myFileSystem.getPath("/usr/local/google/home/testuser/.android/avd/Pixel_2_XL_API_28.avd/snapshots/default_boot"); Object snapshot = myTask.getSnapshot(directory); assertEquals(Snapshot.quickboot(myFileSystem), snapshot); }
@Test public void getSnapshotImageCountEqualsZero() { SnapshotOuterClass.Snapshot protocolBufferSnapshot = SnapshotOuterClass.Snapshot.getDefaultInstance(); Path directory = myFileSystem.getPath(""); Object snapshot = myTask.getSnapshot(protocolBufferSnapshot, directory); assertNull(snapshot); }
@Test public void getSnapshotLogicalNameIsEmpty() { SnapshotOuterClass.Snapshot protocolBufferSnapshot = SnapshotOuterClass.Snapshot.newBuilder() .addImages(Image.getDefaultInstance()) .build(); Path directory = Snapshot.defaultBoot(myFileSystem); Object snapshot = myTask.getSnapshot(protocolBufferSnapshot, directory); assertEquals(Snapshot.quickboot(myFileSystem), snapshot); }
@Test public void getSnapshot() { SnapshotOuterClass.Snapshot protocolBufferSnapshot = SnapshotOuterClass.Snapshot.newBuilder() .addImages(Image.getDefaultInstance()) .setLogicalName("My Snapshot") .build(); Path directory = myFileSystem.getPath(""); Object snapshot = myTask.getSnapshot(protocolBufferSnapshot, directory); assertEquals(new Snapshot(directory, "My Snapshot"), snapshot); }