AdbFileOperations { public ListenableFuture<List<String>> listPackages() { return myExecutor.executeAsync(() -> { String command = getCommand(null, "pm list packages").build(); AdbShellCommandResult commandResult = AdbShellCommandsUtil.executeCommand(myDevice, command); commandResult.throwIfError(); return commandResult.getOutput().stream() .map(AdbFileOperations::processPackageListLine) .filter(x -> !StringUtil.isEmpty(x)) .collect(Collectors.toList()); }); } AdbFileOperations(@NotNull IDevice device, @NotNull AdbDeviceCapabilities deviceCapabilities, @NotNull Executor taskExecutor); @NotNull ListenableFuture<Void> createNewFile(@NotNull String parentPath, @NotNull String fileName); @NotNull ListenableFuture<Void> createNewFileRunAs(@NotNull String parentPath, @NotNull String fileName, @Nullable String runAs); @NotNull ListenableFuture<Void> createNewDirectory(@NotNull String parentPath, @NotNull String directoryName); @NotNull ListenableFuture<Void> createNewDirectoryRunAs(@NotNull String parentPath, @NotNull String directoryName, @Nullable String runAs); ListenableFuture<List<String>> listPackages(); ListenableFuture<List<PackageInfo>> listPackageInfo(); @NotNull ListenableFuture<Void> deleteFile(@NotNull String path); @NotNull ListenableFuture<Void> deleteFileRunAs(@NotNull String path, @Nullable String runAs); @NotNull ListenableFuture<Void> deleteRecursive(@NotNull String path); @NotNull ListenableFuture<Void> deleteRecursiveRunAs(@NotNull String path, @Nullable String runAs); @NotNull ListenableFuture<Void> copyFile(@NotNull String source, @NotNull String destination); @NotNull ListenableFuture<Void> copyFileRunAs(@NotNull String source, @NotNull String destination, @Nullable String runAs); @NotNull ListenableFuture<String> createTempFile(@NotNull String tempPath); @SuppressWarnings({"SameParameterValue", "WeakerAccess"}) @NotNull ListenableFuture<String> createTempFileRunAs(@NotNull String tempDirectoy, @Nullable String runAs); @NotNull ListenableFuture<Void> touchFileAsDefaultUser(@NotNull String remotePath);  }
@Test public void testListPackages() throws Exception { AdbFileOperations fileOperations = setupMockDevice(); List<String> result = waitForFuture(fileOperations.listPackages()); assertThat(result).isNotNull(); assertThat(result).contains("com.example.rpaquay.myapplication"); }