DownloadOSFamily implements Comparable<DownloadOSFamily> { final void seal() { Collections.sort(downloads, new Comparator<DownloadOS>() { @Override public int compare(DownloadOS o1, DownloadOS o2) { return o1.compareTo(o2) * -1; } }); sealed = true; } DownloadOSFamily(final String name);  DownloadOSFamily(final String name, final List<DownloadOS> downloads); final String getName(); final List<DownloadOS> getDownloads(); DownloadOS findDownload(final String name); DownloadOS findLatestDownload(final String qualifier); @Override final int hashCode(); @Override final boolean equals(final Object obj); @Override final int compareTo(final DownloadOSFamily other); @Override final String toString();  }
@Test public void testSeal() { final String name = "Linux"; final DownloadOSFamily testee = new DownloadOSFamily(name); final DownloadOS v16 = new DownloadOS("Ubuntu 16.04 64-bit (.deb)", "https: final DownloadOS v18 = new DownloadOS("Ubuntu 18.04 64-bit (.deb)", "https: testee.addOS(v16); testee.seal(); try { testee.addOS(v18); fail(); } catch (final IllegalStateException ex) { assertThat(ex.getMessage()).isEqualTo("The instance is sealed"); } }