### Question:
Delta { @Nonnull public final Version infer(@Nonnull final Version previous) { if (previous == null) { throw new IllegalArgumentException("null previous"); } if (previous.isInDevelopment()) { throw new IllegalArgumentException("Cannot infer for in development version <"+previous+">"); } final CompatibilityType compatibilityType = computeCompatibilityType(); return inferNextVersion(previous, compatibilityType); } Delta(@Nonnull final Set<? extends Difference> differences); @Nonnull final Set<Difference> getDifferences(); @Nonnull final CompatibilityType computeCompatibilityType(); @Nonnull static Version inferNextVersion(@Nonnull final Version version, @Nonnull final CompatibilityType compatibilityType); @Nonnull final Version infer(@Nonnull final Version previous); final boolean validate(@Nonnull final Version previous, @Nonnull final Version current);  }### Answer:
@Test(expected=IllegalArgumentException.class) public void shouldNullVersionNotBeInferable() { new Delta(EMPTY_DIFFERENCES).infer(null); }
@Test(expected=IllegalArgumentException.class) public void shouldDevelopmentVersionNotBeInferable() { new Delta(EMPTY_DIFFERENCES).infer(new Version(0, 0, 0)); }
@Test public void shouldEmptyDeltaBeImplementerBackwardCompatible() { final int major = 1; final int minor = 2; final int patch = 3; final Version version = new Version(major, minor, patch); final Version inferedVersion = new Delta(EMPTY_DIFFERENCES).infer(version); assertEquals(new Version(major, minor, patch+1), inferedVersion); }
@Test public void shouldDeltaWithAddsBeUserBackwardCompatible() { final int major = 1; final int minor = 2; final int patch = 3; final Version version = new Version(major, minor, patch); final Version inferedVersion = new Delta(Collections.singleton(new Delta.Add("class", new FieldInfo(0, "", "", "", null)))).infer(version); assertEquals(new Version(major, minor+1, 0), inferedVersion); }
@Test public void shouldDeltaWithChangesBeNonBackwardCompatible() { final int major = 1; final int minor = 2; final int patch = 3; final Version version = new Version(major, minor, patch); final Version inferedVersion = new Delta(Collections.singleton(new Delta.Change("class", new FieldInfo(0, "", "", "", null), new FieldInfo(0, "", "", "", null)))).infer(version); assertEquals(new Version(major+1, 0, 0), inferedVersion); }
@Test public void shouldDeltaWithRemovesBeNonBackwardCompatible() { final int major = 1; final int minor = 2; final int patch = 3; final Version version = new Version(major, minor, patch); final Version inferedVersion = new Delta(Collections.singleton(new Delta.Remove("class", new FieldInfo(0, "", "", "", null)))).infer(version); assertEquals(new Version(major+1, 0, 0), inferedVersion); }