diff options
Diffstat (limited to 'api')
-rwxr-xr-x | api/src/main/java/org/semver/Delta.java | 17 | ||||
-rwxr-xr-x | api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java | 6 | ||||
-rwxr-xr-x | api/src/test/java/org/semver/DeltaTest.java | 22 |
3 files changed, 29 insertions, 16 deletions
diff --git a/api/src/main/java/org/semver/Delta.java b/api/src/main/java/org/semver/Delta.java index e148a72..6ef79fd 100755 --- a/api/src/main/java/org/semver/Delta.java +++ b/api/src/main/java/org/semver/Delta.java @@ -151,9 +151,11 @@ public final class Delta { } private final Set<Difference> differences; + private final boolean fieldCompatChanged; - public Delta(@Nonnull final Set<? extends Difference> differences) { + public Delta(@Nonnull final Set<? extends Difference> differences, final boolean fieldCompatChanged) { this.differences = Collections.unmodifiableSet(differences); + this.fieldCompatChanged = fieldCompatChanged; } @Nonnull @@ -161,9 +163,10 @@ public final class Delta { return this.differences; } + public final boolean fieldCompatChanged() { return fieldCompatChanged; } + /** - * @param differences - * @return {@link CompatibilityType} based on specified {@link Difference} + * @return {@link CompatibilityType} based on this {@link Delta} */ @Nonnull public final CompatibilityType computeCompatibilityType() { @@ -180,6 +183,14 @@ public final class Delta { } } + /** + * @param type {@link Difference} type to test + * @return {@code true}, if given {@link Difference} type is contained by this {@link Delta} + */ + public final boolean contains(final Class<? extends Difference> type) { + return contains(this.differences, type); + } + protected final boolean contains(final Set<Difference> differences, final Class<? extends Difference> type) { for (final Difference difference : differences) { if (type.isInstance(difference)) { diff --git a/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java b/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java index 8f7fb22..f697ef4 100755 --- a/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java +++ b/api/src/main/java/org/semver/jardiff/DifferenceAccumulatingHandler.java @@ -49,6 +49,7 @@ public final class DifferenceAccumulatingHandler extends AbstractDiffHandler { private final Set<String> excludes; private final boolean excludesAreRegExp; private final Set<Difference> differences = new HashSet<Difference>(); + private boolean fieldCompatChanged; public DifferenceAccumulatingHandler() { this(Collections.<String>emptySet(), Collections.<String>emptySet()); @@ -63,6 +64,7 @@ public final class DifferenceAccumulatingHandler extends AbstractDiffHandler { this.includesAreRegExp = includesAreRegExp; this.excludes = excludes; this.excludesAreRegExp = excludesAreRegExp; + this.fieldCompatChanged = false; } public String getCurrentClassName() { @@ -173,7 +175,7 @@ public final class DifferenceAccumulatingHandler extends AbstractDiffHandler { if (!isClassConsidered(getCurrentClassName())) { return; } - + this.fieldCompatChanged = true; this.differences.add(new CompatChange(getCurrentClassName(), oldFieldInfo, newFieldInfo)); } @@ -354,7 +356,7 @@ public final class DifferenceAccumulatingHandler extends AbstractDiffHandler { } public Delta getDelta() { - return new Delta(this.differences); + return new Delta(this.differences, this.fieldCompatChanged); } } diff --git a/api/src/test/java/org/semver/DeltaTest.java b/api/src/test/java/org/semver/DeltaTest.java index 0c99636..6548e61 100755 --- a/api/src/test/java/org/semver/DeltaTest.java +++ b/api/src/test/java/org/semver/DeltaTest.java @@ -64,12 +64,12 @@ public class DeltaTest { @Test(expected=IllegalArgumentException.class) public void shouldNullVersionNotBeInferable() { - new Delta(EMPTY_DIFFERENCES).infer(null); + new Delta(EMPTY_DIFFERENCES, false).infer(null); } @Test(expected=IllegalArgumentException.class) public void shouldDevelopmentVersionNotBeInferable() { - new Delta(EMPTY_DIFFERENCES).infer(new Version(0, 0, 0)); + new Delta(EMPTY_DIFFERENCES, false).infer(new Version(0, 0, 0)); } @Test @@ -79,7 +79,7 @@ public class DeltaTest { final int patch = 3; final Version version = new Version(major, minor, patch); - final Version inferedVersion = new Delta(EMPTY_DIFFERENCES).infer(version); + final Version inferedVersion = new Delta(EMPTY_DIFFERENCES, false).infer(version); assertEquals(new Version(major, minor, patch+1), inferedVersion); } @@ -91,7 +91,7 @@ public class DeltaTest { 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); + final Version inferedVersion = new Delta(Collections.singleton(new Delta.Add("class", new FieldInfo(0, "", "", "", null))), false).infer(version); assertEquals(new Version(major, minor+1, 0), inferedVersion); } @@ -103,7 +103,7 @@ public class DeltaTest { 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); + final Version inferedVersion = new Delta(Collections.singleton(new Delta.Change("class", new FieldInfo(0, "", "", "", null), new FieldInfo(0, "", "", "", null))), false).infer(version); assertEquals(new Version(major+1, 0, 0), inferedVersion); } @@ -115,19 +115,19 @@ public class DeltaTest { 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); + final Version inferedVersion = new Delta(Collections.singleton(new Delta.Remove("class", new FieldInfo(0, "", "", "", null))), false).infer(version); assertEquals(new Version(major+1, 0, 0), inferedVersion); } @Test(expected=IllegalArgumentException.class) public void shouldValidateWithNullPreviousVersionFail() { - new Delta(EMPTY_DIFFERENCES).validate(null, new Version(1, 0, 0)); + new Delta(EMPTY_DIFFERENCES, false).validate(null, new Version(1, 0, 0)); } @Test(expected=IllegalArgumentException.class) public void shouldValidateWithNullCurrentVersionFail() { - new Delta(EMPTY_DIFFERENCES).validate(new Version(1, 0, 0), null); + new Delta(EMPTY_DIFFERENCES, false).validate(new Version(1, 0, 0), null); } @Test @@ -137,12 +137,12 @@ public class DeltaTest { @Test(expected=IllegalArgumentException.class) public void shouldValidateWithPreviousVersionNextCurrentVersionFail() { - new Delta(EMPTY_DIFFERENCES).validate(new Version(1, 1, 0), new Version(1, 0, 0)); + new Delta(EMPTY_DIFFERENCES, false).validate(new Version(1, 1, 0), new Version(1, 0, 0)); } @Test(expected=IllegalArgumentException.class) public void shouldValidateWithPreviousVersionEqualsCurrentVersionFail() { - new Delta(EMPTY_DIFFERENCES).validate(new Version(1, 0, 0), new Version(1, 0, 0)); + new Delta(EMPTY_DIFFERENCES, false).validate(new Version(1, 0, 0), new Version(1, 0, 0)); } @Test @@ -179,6 +179,6 @@ public class DeltaTest { assertEquals( "accept differences " + differences + " when changing version from " + previous + " to " + current, valid, - new Delta(differences).validate(previous, current)); + new Delta(differences, false).validate(previous, current)); } }
\ No newline at end of file |