ScreenRecorderAction extends AbstractDeviceAction { @Override public void update(@NotNull AnActionEvent event) { Presentation presentation = event.getPresentation(); if (!isEnabled()) { presentation.setEnabled(false); presentation.setText(AndroidBundle.messagePointer("android.ddms.actions.screenrecord")); return; } IDevice device = myDeviceContext.getSelectedDevice(); if (myFeatures.watch(device)) { presentation.setEnabled(false); presentation.setText("Screen Record Is Unavailable for Wear OS"); return; } presentation.setEnabled(myFeatures.screenRecord(device)); presentation.setText(AndroidBundle.messagePointer("android.ddms.actions.screenrecord")); } ScreenRecorderAction(@NotNull Project project, @NotNull DeviceContext context); @VisibleForTesting  ScreenRecorderAction(@NotNull Project project, @NotNull DeviceContext context, @NotNull Features features); @Override void update(@NotNull AnActionEvent event);  }
@Test public void updateIsntEnabled() { new ScreenRecorderAction(myRule.getProject(), myContext, myFeatures).update(myEvent); assertFalse(myPresentation.isEnabled()); assertEquals("Screen Record", myPresentation.getText()); }
@Test public void updateDeviceIsWatch() { IDevice device = Mockito.mock(IDevice.class); Mockito.when(device.isOnline()).thenReturn(true); Mockito.when(myContext.getSelectedDevice()).thenReturn(device); Mockito.when(myFeatures.watch(device)).thenReturn(true); new ScreenRecorderAction(myRule.getProject(), myContext, myFeatures).update(myEvent); assertFalse(myPresentation.isEnabled()); assertEquals("Screen Record Is Unavailable for Wear OS", myPresentation.getText()); }
@Test public void updateDeviceDoesntHaveScreenRecord() { IDevice device = Mockito.mock(IDevice.class); Mockito.when(device.isOnline()).thenReturn(true); Mockito.when(myContext.getSelectedDevice()).thenReturn(device); new ScreenRecorderAction(myRule.getProject(), myContext, myFeatures).update(myEvent); assertFalse(myPresentation.isEnabled()); assertEquals("Screen Record", myPresentation.getText()); }
@Test public void updateDeviceHasScreenRecord() { IDevice device = Mockito.mock(IDevice.class); Mockito.when(device.isOnline()).thenReturn(true); Mockito.when(myContext.getSelectedDevice()).thenReturn(device); Mockito.when(myFeatures.screenRecord(device)).thenReturn(true); new ScreenRecorderAction(myRule.getProject(), myContext, myFeatures).update(myEvent); assertTrue(myPresentation.isEnabled()); assertEquals("Screen Record", myPresentation.getText()); }