ScreenRecorderAction extends AbstractDeviceAction { @Nullable @VisibleForTesting Path getTemporaryVideoPathForVirtualDevice(@NotNull IDevice device, @NotNull AvdManager manager) { if (!myFeatures.screenRecord(device)) { return null; } AvdInfo virtualDevice = manager.getAvd(device.getAvdName(), true); if (virtualDevice == null) { return null; } return Paths.get(virtualDevice.getDataFolderPath(), EMU_TMP_FILENAME); } 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 getTemporaryVideoPathDeviceDoesntHaveScreenRecord() { ScreenRecorderAction action = new ScreenRecorderAction(myRule.getProject(), myContext, myFeatures); IDevice device = Mockito.mock(IDevice.class); AvdManager manager = Mockito.mock(AvdManager.class); Object path = action.getTemporaryVideoPathForVirtualDevice(device, manager); assertNull(path); }
@Test public void getTemporaryVideoPathForVirtualDeviceVirtualDeviceIsNull() { ScreenRecorderAction action = new ScreenRecorderAction(myRule.getProject(), myContext, myFeatures); IDevice device = Mockito.mock(IDevice.class); AvdManager manager = Mockito.mock(AvdManager.class); Mockito.when(myFeatures.screenRecord(device)).thenReturn(true); Object path = action.getTemporaryVideoPathForVirtualDevice(device, manager); assertNull(path); }
@Test public void getTemporaryVideoPathForVirtualDevice() { ScreenRecorderAction action = new ScreenRecorderAction(myRule.getProject(), myContext, myFeatures); IDevice device = Mockito.mock(IDevice.class); AvdManager manager = Mockito.mock(AvdManager.class); AvdInfo virtualDevice = new AvdInfo( "Pixel_2_XL_API_28", new File("/usr/local/google/home/juancnuno/.android/avd/Pixel_2_XL_API_28.ini"), "/usr/local/google/home/juancnuno/.android/avd/Pixel_2_XL_API_28.avd", Mockito.mock(ISystemImage.class), null); Mockito.when(myFeatures.screenRecord(device)).thenReturn(true); Mockito.when(manager.getAvd(device.getAvdName(), true)).thenReturn(virtualDevice); Object path = action.getTemporaryVideoPathForVirtualDevice(device, manager); assertEquals(Paths.get("/usr/local/google/home/juancnuno/.android/avd/Pixel_2_XL_API_28.avd/tmp.webm"), path); }