DeliverablePackage implements Comparable<DeliverablePackage> { @Override public int compareTo(@NotNull DeliverablePackage deliverablePackage) { if(reference().getId().equals(deliverablePackage.reference().getId())){ if (getVersion() != null && deliverablePackage.getVersion() != null){ return getVersion().compareTo(deliverablePackage.getVersion()); } return 0; } return reference().getId().compareTo(deliverablePackage.reference().getId()); } <T extends Deliverable> DeliverablePackage(Deliverable installedDeliverable, Path deliverableDir, DeliverableRegistry<T> deliverableRegistry); boolean isInstalled(); Deliverable reference(); void displayInformation(); String getId(); String getName(); String getDescription(); URL getUrl(); Deliverable.Type getType(); String getVersion(); String getInstalledVersion(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(@NotNull DeliverablePackage deliverablePackage);  }
@Test public void test_compare_deliverables_with_id() throws IOException { ExtensionService extensionService = new ExtensionService(deliverableDir.getRoot().toPath()); DeliverablePackage deliverablePackageA = new DeliverablePackage(extensionService.newDeliverable(deliverableDir.newFile( "my-extension-A.jar").toURI().toURL()),deliverableDir.getRoot().toPath(),extensionService.deliverableRegistry); DeliverablePackage deliverablePackageB = new DeliverablePackage(extensionService.newDeliverable(deliverableDir.newFile( "my-extension-B.jar").toURI().toURL()),deliverableDir.getRoot().toPath(),extensionService.deliverableRegistry); assertThat(deliverablePackageA.compareTo(deliverablePackageB)).isLessThan(0); }
@Test public void test_compare_deliverables_with_same_id_different_version() throws IOException { ExtensionService extensionService = new ExtensionService(deliverableDir.getRoot().toPath()); DeliverablePackage deliverablePackageA = new DeliverablePackage(extensionService.newDeliverable(deliverableDir.newFile( "my-extension-1.jar").toURI().toURL()),deliverableDir.getRoot().toPath(),extensionService.deliverableRegistry); DeliverablePackage deliverablePackageB = new DeliverablePackage(extensionService.newDeliverable(deliverableDir.newFile( "my-extension-2.jar").toURI().toURL()),deliverableDir.getRoot().toPath(),extensionService.deliverableRegistry); assertThat(deliverablePackageA.compareTo(deliverablePackageB)).isLessThan(0); }