DeviceAndSnapshotComboBoxAction extends ComboBoxAction { @VisibleForTesting static void updatePresentation(@NotNull Presentation presentation, @Nullable RunnerAndConfigurationSettings settings) { if (settings == null) { presentation.setDescription("Add a run/debug configuration"); presentation.setEnabled(false); return; } RunProfile configuration = settings.getConfiguration(); if (configuration instanceof UserDataHolder) { Boolean deploysToLocalDevice = ((UserDataHolder)configuration).getUserData(DEPLOYS_TO_LOCAL_DEVICE); if (deploysToLocalDevice != null && deploysToLocalDevice.booleanValue()) { presentation.setDescription(Presentation.NULL_STRING); presentation.setEnabled(true); return; } } if (!(configuration instanceof AndroidRunConfiguration || configuration instanceof AndroidTestRunConfiguration)) { presentation.setDescription("Not applicable for the \"" + configuration.getName() + "\" configuration"); presentation.setEnabled(false); return; } presentation.setDescription(Presentation.NULL_STRING); presentation.setEnabled(true); } @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 updatePresentationSettingsIsNull() { DeviceAndSnapshotComboBoxAction.updatePresentation(myPresentation, null); assertEquals("Add a run/debug configuration", myPresentation.getDescription()); assertFalse(myPresentation.isEnabled()); }
@Test public void updatePresentationConfigurationIsntAndroidRunConfigurationNorAndroidTestRunConfiguration() { RunConfiguration configuration = Mockito.mock(RunConfiguration.class); Mockito.when(configuration.getName()).thenReturn("ExampleUnitTest"); RunnerAndConfigurationSettings settings = Mockito.mock(RunnerAndConfigurationSettings.class); Mockito.when(settings.getConfiguration()).thenReturn(configuration); DeviceAndSnapshotComboBoxAction.updatePresentation(myPresentation, settings); assertEquals("Not applicable for the \"ExampleUnitTest\" configuration", myPresentation.getDescription()); assertFalse(myPresentation.isEnabled()); }
@Test public void updatePresentationConfigurationIsntAndroidRunConfigurationNorAndroidTestRunConfigurationButDeploysToLocalDevice() { RunConfigurationBase configuration = Mockito.mock(RunConfigurationBase.class); Mockito.when(configuration.getUserData(DeviceAndSnapshotComboBoxAction.DEPLOYS_TO_LOCAL_DEVICE)).thenReturn(true); RunnerAndConfigurationSettings settings = Mockito.mock(RunnerAndConfigurationSettings.class); Mockito.when(settings.getConfiguration()).thenReturn(configuration); DeviceAndSnapshotComboBoxAction.updatePresentation(myPresentation, settings); assertNull(myPresentation.getDescription()); assertTrue(myPresentation.isEnabled()); }
@Test public void updatePresentationFirebaseTestLabDeviceMatrixTargetIsntSelected() { DeployTargetContext context = Mockito.mock(DeployTargetContext.class); Mockito.when(context.getCurrentDeployTargetProvider()).thenReturn(new DeviceAndSnapshotComboBoxTargetProvider()); AndroidRunConfigurationBase configuration = Mockito.mock(AndroidTestRunConfiguration.class); Mockito.when(configuration.getDeployTargetContext()).thenReturn(context); RunnerAndConfigurationSettings settings = Mockito.mock(RunnerAndConfigurationSettings.class); Mockito.when(settings.getConfiguration()).thenReturn(configuration); DeviceAndSnapshotComboBoxAction.updatePresentation(myPresentation, settings); assertNull(myPresentation.getDescription()); assertTrue(myPresentation.isEnabled()); }
@Test public void updatePresentation() { RunConfiguration configuration = Mockito.mock(AndroidRunConfiguration.class); RunnerAndConfigurationSettings settings = Mockito.mock(RunnerAndConfigurationSettings.class); Mockito.when(settings.getConfiguration()).thenReturn(configuration); DeviceAndSnapshotComboBoxAction.updatePresentation(myPresentation, settings); assertNull(myPresentation.getDescription()); assertTrue(myPresentation.isEnabled()); }