VersionedMessage { public int compareVersion(MessageVersion compareToVersion) { return version.compareTo(compareToVersion); } VersionedMessage(MessageVersion version, T message); int compareVersion(MessageVersion compareToVersion); MessageVersion getVersion(); T getMessage();  }
@Test public void testCompareVersion() throws Exception { MessageVersion version1 = new MessageVersion("1.0.0"); MessageVersion version2 = new MessageVersion("2.0.0"); MessageVersion version3 = new MessageVersion("0.5.0"); VersionedMessage<String> versionedMessage = new VersionedMessage<>(version1, "a"); assertTrue(versionedMessage.compareVersion(version1) == 0); assertTrue(versionedMessage.compareVersion(version2) < 0); assertTrue(versionedMessage.compareVersion(version3) > 0); }