AndroidProfilerToolWindow implements Disposable { @NotNull static String getDeviceDisplayName(@NotNull IDevice device) { StringBuilder deviceNameBuilder = new StringBuilder(); String manufacturer = TransportServiceProxy.getDeviceManufacturer(device); String model = TransportServiceProxy.getDeviceModel(device); String serial = device.getSerialNumber(); String suffix = String.format("-%s", serial); if (model.endsWith(suffix)) { model = model.substring(0, model.length() - suffix.length()); } if (!StringUtil.isEmpty(manufacturer)) { deviceNameBuilder.append(manufacturer); deviceNameBuilder.append(" "); } deviceNameBuilder.append(model); return deviceNameBuilder.toString(); } AndroidProfilerToolWindow(@NotNull ToolWindow window, @NotNull Project project); void profile(@NotNull PreferredProcessInfo processInfo); void openFile(@NotNull VirtualFile file); @Override void dispose(); @NotNull JComponent getComponent();  }
@Test public void testDeviceDisplayName() { IDevice device = mock(IDevice.class); when(device.getSerialNumber()).thenReturn("Serial"); when(device.getProperty(IDevice.PROP_DEVICE_MANUFACTURER)).thenReturn("Manufacturer"); when(device.getProperty(IDevice.PROP_DEVICE_MODEL)).thenReturn("Model"); assertThat(AndroidProfilerToolWindow.getDeviceDisplayName(device)).isEqualTo("Manufacturer Model"); IDevice deviceWithEmptyManufacturer = mock(IDevice.class); when(deviceWithEmptyManufacturer.getSerialNumber()).thenReturn("Serial"); when(deviceWithEmptyManufacturer.getProperty(IDevice.PROP_DEVICE_MODEL)).thenReturn("Model"); assertThat(AndroidProfilerToolWindow.getDeviceDisplayName(deviceWithEmptyManufacturer)).isEqualTo("Model"); IDevice deviceWithSerialInModel = mock(IDevice.class); when(deviceWithSerialInModel.getSerialNumber()).thenReturn("Serial"); when(deviceWithSerialInModel.getProperty(IDevice.PROP_DEVICE_MANUFACTURER)).thenReturn("Manufacturer"); when(deviceWithSerialInModel.getProperty(IDevice.PROP_DEVICE_MODEL)).thenReturn("Model-Serial"); assertThat(AndroidProfilerToolWindow.getDeviceDisplayName(deviceWithSerialInModel)).isEqualTo("Manufacturer Model"); }