DeviceAndSnapshotComboBoxAction extends ComboBoxAction { @Override public final void update(@NotNull AnActionEvent event) { Presentation presentation = event.getPresentation(); Project project = event.getProject(); if (project == null) { presentation.setVisible(false); return; } if (!AndroidUtils.hasAndroidFacets(project)) { presentation.setVisible(false); return; } updatePresentation(presentation, RunManager.getInstance(project).getSelectedConfiguration()); List<Device> devices = getDevices(project); Device device = getSelectedDevice(project, devices); if (event.getPlace().equals(ActionPlaces.MAIN_MENU)) { presentation.setIcon(null); presentation.setText("Select Device..."); } else if (devices.isEmpty()) { presentation.setIcon(null); presentation.setText("No Devices"); } else { assert device != null; presentation.setIcon(device.getIcon()); presentation.setText(getText(device, devices, mySelectDeviceSnapshotComboBoxSnapshotsEnabled.get()), false); } updateExecutionTargetManager(project, device); } @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 updateDevicesGetterReturnsDifferentLists() { Device device = new PhysicalDevice.Builder() .setName("Unknown Device") .setKey(new Key("cd020375-1ce4-45dc-a5be-b45e5765c6f2")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Mockito.when(myDevicesGetter.get()) .thenReturn(Collections.emptyList()) .thenReturn(Collections.singletonList(device)); AnAction action = new DeviceAndSnapshotComboBoxAction(() -> false, project -> myDevicesGetter, project -> null, myClock); action.update(myEvent); }