AsyncDevicesGetter { @NotNull @VisibleForTesting List<Device> getImpl(@NotNull Collection<VirtualDevice> virtualDevices, @NotNull Collection<ConnectedDevice> connectedDevices) { @SuppressWarnings("UnstableApiUsage") Stream<Device> deviceStream = Streams.concat( connectedVirtualDeviceStream(connectedDevices, virtualDevices), physicalDeviceStream(connectedDevices), disconnectedVirtualDeviceStream(virtualDevices, connectedDevices)); List<Device> devices = deviceStream.collect(Collectors.toList()); Collection<Key> keys = devices.stream() .filter(Device::isConnected) .map(Device::getKey) .collect(Collectors.toList()); myMap.retainAll(keys); return devices; } @SuppressWarnings("unused") private  AsyncDevicesGetter(@NotNull Project project); @NonInjectable @VisibleForTesting  AsyncDevicesGetter(@NotNull Project project,
                     @NotNull BooleanSupplier selectDeviceSnapshotComboBoxSnapshotsEnabled,
                     @NotNull KeyToConnectionTimeMap map,
                     @NotNull Function<ConnectedDevice, String> getName);   }
@Test public void getImpl() { AndroidDevice pixel2ApiQAndroidDevice = Mockito.mock(AndroidDevice.class); VirtualDevice pixel2ApiQVirtualDevice = new VirtualDevice.Builder() .setName("Pixel 2 API Q") .setKey(new Key("Pixel_2_API_Q")) .setAndroidDevice(pixel2ApiQAndroidDevice) .build(); VirtualDevice pixel3ApiQVirtualDevice = new VirtualDevice.Builder() .setName("Pixel 3 API Q") .setKey(new Key("Pixel_3_API_Q")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); AndroidDevice googlePixel3AndroidDevice = Mockito.mock(AndroidDevice.class); ConnectedDevice googlePixel3ConnectedDevice = new ConnectedDevice.Builder() .setName("Physical Device") .setKey(new Key("86UX00F4R")) .setAndroidDevice(googlePixel3AndroidDevice) .build(); Mockito.when(myGetName.apply(googlePixel3ConnectedDevice)).thenReturn("Google Pixel 3"); AndroidDevice pixel3ApiQAndroidDevice = Mockito.mock(AndroidDevice.class); Mockito.when(pixel3ApiQAndroidDevice.isVirtual()).thenReturn(true); ConnectedDevice pixel3ApiQConnectedDevice = new ConnectedDevice.Builder() .setName("Virtual Device") .setKey(new Key("Pixel_3_API_Q")) .setAndroidDevice(pixel3ApiQAndroidDevice) .build(); Object actualDevices = myGetter.getImpl( Arrays.asList(pixel2ApiQVirtualDevice, pixel3ApiQVirtualDevice), Arrays.asList(googlePixel3ConnectedDevice, pixel3ApiQConnectedDevice)); Object expectedPixel3ApiQDevice = new VirtualDevice.Builder() .setName("Pixel 3 API Q") .setKey(new Key("Pixel_3_API_Q")) .setConnectionTime(Instant.parse("2018-11-28T01:15:27.000Z")) .setAndroidDevice(pixel3ApiQAndroidDevice) .build(); Object expectedGooglePixel3Device = new PhysicalDevice.Builder() .setName("Google Pixel 3") .setKey(new Key("86UX00F4R")) .setConnectionTime(Instant.parse("2018-11-28T01:15:27.000Z")) .setAndroidDevice(googlePixel3AndroidDevice) .build(); Object expectedPixel2ApiQDevice = new VirtualDevice.Builder() .setName("Pixel 2 API Q") .setKey(new Key("Pixel_2_API_Q")) .setAndroidDevice(pixel2ApiQAndroidDevice) .build(); assertEquals(Arrays.asList(expectedPixel3ApiQDevice, expectedGooglePixel3Device, expectedPixel2ApiQDevice), actualDevices); }
@Test public void getImplDeveloperBuiltTheirOwnSystemImage() { AndroidDevice androidDevice = Mockito.mock(AndroidDevice.class); Mockito.when(androidDevice.isVirtual()).thenReturn(true); ConnectedDevice connectedDevice = new ConnectedDevice.Builder() .setName("Virtual Device") .setKey(new Key("emulator-5554")) .setAndroidDevice(androidDevice) .build(); Object actualDevices = myGetter.getImpl(Collections.emptyList(), Collections.singletonList(connectedDevice)); Object expectedDevice = new VirtualDevice.Builder() .setName("Virtual Device") .setKey(new Key("emulator-5554")) .setConnectionTime(Instant.parse("2018-11-28T01:15:27.000Z")) .setAndroidDevice(androidDevice) .build(); assertEquals(Collections.singletonList(expectedDevice), actualDevices); }