NameGetter implements Function<ConnectedDevice, String> { @NotNull @VisibleForTesting static String getName(@NotNull DeviceNameProperties properties) { String manufacturer = properties.getManufacturer(); String model = properties.getModel(); if (manufacturer == null && model == null) { return "Physical Device"; } if (manufacturer == null) { return model; } if (model == null) { return manufacturer + " Device"; } return manufacturer + ' ' + model; } NameGetter(@NotNull Disposable parent); @NotNull @Override String apply(@NotNull ConnectedDevice device);  }
@Test public void getNameManufacturerAndModelAreNull() { DeviceNameProperties properties = new DeviceNameProperties(null, null, null, null); Object name = NameGetter.getName(properties); assertEquals("Physical Device", name); }
@Test public void getNameManufacturerIsNull() { DeviceNameProperties properties = new DeviceNameProperties("Nexus 5X", null, null, null); Object name = NameGetter.getName(properties); assertEquals("Nexus 5X", name); }
@Test public void getNameModelIsNull() { DeviceNameProperties properties = new DeviceNameProperties(null, "LGE", null, null); Object name = NameGetter.getName(properties); assertEquals("LGE Device", name); }
@Test public void getName() { DeviceNameProperties properties = new DeviceNameProperties("Nexus 5X", "LGE", null, null); Object name = NameGetter.getName(properties); assertEquals("LGE Nexus 5X", name); }