DeviceAndSnapshotComboBoxAction extends ComboBoxAction { @NotNull @VisibleForTesting static String getText(@NotNull Device device, @NotNull Collection<Device> devices, boolean snapshotsEnabled) { boolean anotherDeviceHasSameName = Devices.containsAnotherDeviceWithSameName(devices, device); return Devices.getText(device, anotherDeviceHasSameName ? device.getKey() : null, snapshotsEnabled ? device.getSnapshot() : null); } @SuppressWarnings("unused") private  DeviceAndSnapshotComboBoxAction(); @VisibleForTesting  DeviceAndSnapshotComboBoxAction(@NotNull Supplier<Boolean> selectDeviceSnapshotComboBoxSnapshotsEnabled,
                                         @NotNull Function<Project, AsyncDevicesGetter> devicesGetterGetter,
                                         @NotNull Function<Project, PropertiesComponent> getProperties,
                                         @NotNull Clock clock); @NotNull @Override final JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place); @Override final void update(@NotNull AnActionEvent event); static final com.intellij.openapi.util.Key<Boolean> DEPLOYS_TO_LOCAL_DEVICE; }
@Test public void getTextDeviceHasSnapshot() { Snapshot snapshot = new Snapshot(FileSystems.getDefault().getPath("snap_2019-09-27_15-48-09"), "Snapshot"); Device device = new VirtualDevice.Builder() .setName("Pixel 3 API 29") .setKey(new Key("Pixel_3_API_29", snapshot)) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .setSnapshot(snapshot) .build(); Object text = DeviceAndSnapshotComboBoxAction.getText(device, Collections.singletonList(device), true); assertEquals("Pixel 3 API 29 - Snapshot", text); }
@Test public void getTextDeviceHasValidityReason() { Device device = new VirtualDevice.Builder() .setName("Pixel 3 API 29") .setValidityReason("Missing system image") .setKey(new Key("Pixel_3_API_29")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Object text = DeviceAndSnapshotComboBoxAction.getText(device, Collections.singletonList(device), true); assertEquals("Pixel 3 API 29 (Missing system image)", text); }