ConnectedDevicesTask implements AsyncSupplier<List<ConnectedDevice>> { @NotNull @Override public ListenableFuture<List<ConnectedDevice>> get() { ListenableFuture<Collection<IDevice>> devices = myAndroidDebugBridge.getConnectedDevices(); return Futures.transformAsync(devices, this::newConnectedDevices, myExecutor); } ConnectedDevicesTask(@NotNull AndroidDebugBridge androidDebugBridge,
                       boolean selectDeviceSnapshotComboBoxSnapshotsEnabled,
                       @Nullable LaunchCompatibilityChecker checker); @VisibleForTesting  ConnectedDevicesTask(@NotNull AndroidDebugBridge androidDebugBridge,
                       boolean selectDeviceSnapshotComboBoxSnapshotsEnabled,
                       @Nullable LaunchCompatibilityChecker checker,
                       @NotNull Executor executor,
                       @NotNull Function<IDevice, AndroidDevice> androidDeviceFactory); @NotNull @Override ListenableFuture<List<ConnectedDevice>> get();  }
@Test public void get() throws Exception { IDevice device = Mockito.mock(IDevice.class); Mockito.when(myAndroidDebugBridge.getConnectedDevices()).thenReturn(Futures.immediateFuture(Collections.singletonList(device))); ConnectedDevicesTask task = new ConnectedDevicesTask(myAndroidDebugBridge, true, null, MoreExecutors.directExecutor(), d -> null); Future<List<ConnectedDevice>> devices = task.get(); assertEquals(Collections.emptyList(), devices.get(1, TimeUnit.SECONDS)); }
@Test public void getVirtualDeviceNameIsNull() throws Exception { IDevice ddmlibDevice = Mockito.mock(IDevice.class); Mockito.when(ddmlibDevice.isOnline()).thenReturn(true); Mockito.when(ddmlibDevice.isEmulator()).thenReturn(true); Mockito.when(ddmlibDevice.getSerialNumber()).thenReturn("emulator-5554"); Mockito.when(myAndroidDebugBridge.getConnectedDevices()).thenReturn(Futures.immediateFuture(Collections.singletonList(ddmlibDevice))); AndroidDevice androidDevice = Mockito.mock(AndroidDevice.class); AsyncSupplier task = new ConnectedDevicesTask(myAndroidDebugBridge, false, null, MoreExecutors.directExecutor(), d -> androidDevice); Future connectedDevices = task.get(); Object connectedDevice = new ConnectedDevice.Builder() .setName("Virtual Device") .setKey(new Key("emulator-5554")) .setAndroidDevice(androidDevice) .build(); assertEquals(Collections.singletonList(connectedDevice), connectedDevices.get(1, TimeUnit.SECONDS)); }