### Question:
LongVersion implements Version { @Override public Occurred compare(Version v) { if (null == v) { throw new NullPointerException("Version is not allowed to be null."); } if (v == Version.NEW) { return Occurred.AFTER; } else if (v == Version.ANY) { return Occurred.CONCURRENTLY; } else if (!(v instanceof LongVersion)) { throw new IllegalArgumentException("Invalid version type"); } LongVersion zv = (LongVersion) v; int res = Long.compare(version, zv.version); if (res == 0) { return Occurred.CONCURRENTLY; } else if (res < 0) { return Occurred.BEFORE; } else { return Occurred.AFTER; } } LongVersion(long v); @Override Occurred compare(Version v); long getLongVersion(); LongVersion setLongVersion(long v); @Override String toString();  }### Answer:
@Test public void testNullIntVersion() { LongVersion longVersion = new LongVersion(99); try { longVersion.compare(null); Assert.fail("Should fail comparing with null version."); } catch (NullPointerException npe) { } }
@Test public void testInvalidVersion() { LongVersion longVersion = new LongVersion(99); try { longVersion.compare(v -> Occurred.AFTER); Assert.fail("Should not reach here!"); } catch (IllegalArgumentException iae) { } }
@Test public void testCompare() { LongVersion iv = new LongVersion(99); Assert.assertEquals(Occurred.AFTER, iv.compare(new LongVersion(98))); Assert.assertEquals(Occurred.BEFORE, iv.compare(new LongVersion(100))); Assert.assertEquals(Occurred.CONCURRENTLY, iv.compare(new LongVersion(99))); Assert.assertEquals(Occurred.CONCURRENTLY, iv.compare(Version.ANY)); Assert.assertEquals(Occurred.AFTER, iv.compare(Version.NEW)); }