SelectDeviceAction extends AnAction { @NotNull static AnAction newSelectDeviceAction(@NotNull DeviceAndSnapshotComboBoxAction comboBoxAction, @NotNull Project project, @NotNull Device device) { return new SelectDeviceAction(comboBoxAction, project, device, false); } private  SelectDeviceAction(@NotNull DeviceAndSnapshotComboBoxAction comboBoxAction,
                             @NotNull Project project,
                             @NotNull Device device,
                             boolean snapshotActionGroupChild); @NotNull @VisibleForTesting Device getDevice(); @Override void actionPerformed(@NotNull AnActionEvent event); @Override boolean equals(@Nullable Object object); @Override int hashCode();  }
@Test public void selectDeviceActionTwoDevicesHaveSameName() { Device lgeNexus5x1 = new PhysicalDevice.Builder() .setName("LGE Nexus 5X") .setKey(new Key("00fff9d2279fa601")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Device lgeNexus5x2 = new PhysicalDevice.Builder() .setName("LGE Nexus 5X") .setKey(new Key("00fff9d2279fa602")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Mockito.when(myComboBoxAction.getDevices(myProject)).thenReturn(Arrays.asList(lgeNexus5x1, lgeNexus5x2)); AnAction action = SelectDeviceAction.newSelectDeviceAction(myComboBoxAction, myProject, lgeNexus5x1); assertEquals("LGE Nexus 5X [00fff9d2279fa601]", action.getTemplatePresentation().getText()); }
@Test public void newSelectDeviceActionDeviceHasNondefaultSnapshot() { Mockito.when(myComboBoxAction.areSnapshotsEnabled()).thenReturn(true); Device device = new VirtualDevice.Builder() .setName("Pixel 3 API 29") .setKey(new Key("Pixel_3_API_29/snap_2019-09-27_15-48-09")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .setSnapshot(new Snapshot(Paths.get("snap_2019-09-27_15-48-09"), "Snapshot")) .build(); AnAction action = SelectDeviceAction.newSelectDeviceAction(myComboBoxAction, myProject, device); assertEquals("Pixel 3 API 29 - Snapshot", action.getTemplatePresentation().getText()); }
@Test public void newSelectDeviceActionDeviceHasValidityReason() { Device device = new VirtualDevice.Builder() .setName("Pixel 3 API 29") .setValidityReason("Missing system image") .setKey(new Key("Pixel_3_API_29/snap_2019-09-27_15-48-09")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); AnAction action = SelectDeviceAction.newSelectDeviceAction(myComboBoxAction, myProject, device); assertEquals("Pixel 3 API 29 (Missing system image)", action.getTemplatePresentation().getText()); }
@Test public void configurePresentationSetTextDoesntMangleDeviceName() { Device apiQ64Google = new VirtualDevice.Builder() .setName("apiQ_64_Google") .setKey(new Key("apiQ_64_Google")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Mockito.when(myComboBoxAction.getDevices(myProject)).thenReturn(Collections.singletonList(apiQ64Google)); AnAction action = SelectDeviceAction.newSelectDeviceAction(myComboBoxAction, myProject, apiQ64Google); assertEquals("apiQ_64_Google", action.getTemplatePresentation().getText()); }