DeviceComparator implements Comparator<Device> { @Override public int compare(@NotNull Device device1, @NotNull Device device2) { return COMPARATOR.compare(device1, device2); }  @Override int compare(@NotNull Device device1, @NotNull Device device2);  }
@Test public void compareConnectionTime() { Device device1 = new VirtualDevice.Builder() .setName("Pixel 3 API 28") .setKey(new Key("Pixel_3_API_28")) .setConnectionTime(Instant.parse("2019-06-03T20:57:00.687Z")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Device device2 = new VirtualDevice.Builder() .setName("Pixel 2 XL API 28") .setKey(new Key("Pixel_2_XL_API_28")) .setConnectionTime(Instant.parse("2019-06-03T20:56:58.176Z")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); assertTrue(new DeviceComparator().compare(device1, device2) < 0); }
@Test public void compareConnectionTimeNullsLast() { Device device1 = new VirtualDevice.Builder() .setName("Pixel 3 API 28") .setKey(new Key("Pixel_3_API_28")) .setConnectionTime(Instant.parse("2018-11-28T01:15:27.000Z")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Device device2 = new VirtualDevice.Builder() .setName("Pixel 2 XL API 28") .setKey(new Key("Pixel_2_XL_API_28")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); assertTrue(new DeviceComparator().compare(device1, device2) < 0); }
@Test public void compareValid() { Device device1 = new VirtualDevice.Builder() .setName("Pixel 3 API 28") .setKey(new Key("Pixel_3_API_28")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Device device2 = new VirtualDevice.Builder() .setName("Pixel 2 XL API 28") .setValid(false) .setKey(new Key("Pixel_2_XL_API_28")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); assertTrue(new DeviceComparator().compare(device1, device2) < 0); }
@Test public void compareType() { Device device1 = new VirtualDevice.Builder() .setName("Pixel 3 API 28") .setKey(new Key("Pixel_3_API_28")) .setConnectionTime(Instant.parse("2018-11-28T01:15:27.000Z")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Device device2 = new PhysicalDevice.Builder() .setName("LGE Nexus 5X") .setKey(new Key("00fff9d2279fa601")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); assertTrue(new DeviceComparator().compare(device1, device2) < 0); }
@Test public void compareName() { Device device1 = new VirtualDevice.Builder() .setName("Pixel 2 XL API 28") .setKey(new Key("Pixel_2_XL_API_28")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); Device device2 = new VirtualDevice.Builder() .setName("Pixel 3 API 28") .setKey(new Key("Pixel_3_API_28")) .setAndroidDevice(Mockito.mock(AndroidDevice.class)) .build(); assertTrue(new DeviceComparator().compare(device1, device2) < 0); }