This is an automated email from the ASF dual-hosted git repository.
simonetripodi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new 301f7c4 [feature-diff] enriched FeatureDiff and related tests
301f7c4 is described below
commit 301f7c4d81098ac2f667916e00797efc7a454f49
Author: stripodi <[email protected]>
AuthorDate: Wed Apr 3 18:19:43 2019 +0200
[feature-diff] enriched FeatureDiff and related tests
---
.../org/apache/sling/feature/diff/FeatureDiff.java | 24 +++++++++++++++++++---
.../apache/sling/feature/diff/FeatureDiffTest.java | 18 ++++++++++++++++
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git
a/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
b/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
index c2a72fc..e86a6e2 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
@@ -33,7 +33,11 @@ public final class FeatureDiff {
throw new IllegalArgumentException("Feature comparison has to be
related to different versions of the same Feature.");
}
- FeatureDiff featureDiff = new FeatureDiff();
+ if (previous.getId().equals(current.getId())) {
+ throw new IllegalArgumentException("Input Features refer to the
the same Feature version.");
+ }
+
+ FeatureDiff featureDiff = new FeatureDiff(previous, current);
featureDiff.addSection(new
GenericMapComparator("framework-properties").compare(previous.getFrameworkProperties(),
current.getFrameworkProperties()));
featureDiff.addSection(new
ArtifactsComparator("bundles").apply(previous.getBundles(),
current.getBundles()));
@@ -45,8 +49,22 @@ public final class FeatureDiff {
private final List<DiffSection> diffSections = new LinkedList<>();
- private FeatureDiff() {
- // this class can not be instantiated from outside
+ private final Feature previous;
+
+ private final Feature current;
+
+ // this class can not be instantiated from outside
+ private FeatureDiff(Feature previous, Feature current) {
+ this.previous = previous;
+ this.current = current;
+ }
+
+ public Feature getPrevious() {
+ return previous;
+ }
+
+ public Feature getCurrent() {
+ return current;
}
protected void addSection(DiffSection diffSection) {
diff --git
a/feature-diff/src/test/java/org/apache/sling/feature/diff/FeatureDiffTest.java
b/feature-diff/src/test/java/org/apache/sling/feature/diff/FeatureDiffTest.java
index 0d46c2b..1230240 100644
---
a/feature-diff/src/test/java/org/apache/sling/feature/diff/FeatureDiffTest.java
+++
b/feature-diff/src/test/java/org/apache/sling/feature/diff/FeatureDiffTest.java
@@ -19,6 +19,7 @@ package org.apache.sling.feature.diff;
import static org.apache.sling.feature.diff.FeatureDiff.compareFeatures;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Feature;
@@ -43,6 +44,23 @@ public class FeatureDiffTest {
compareFeatures(previous, current);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void doesNotAcceptSameFeature() {
+ Feature previous = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:1.0.0"));
+ Feature current = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:1.0.0"));
+ compareFeatures(previous, current);
+ }
+
+ @Test
+ public void keepFeatureInputs() {
+ Feature previous = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:0.9.0"));
+ Feature current = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:1.0.0"));
+ FeatureDiff featureDiff = compareFeatures(previous, current);
+ assertTrue(featureDiff.isEmpty());
+ assertEquals(previous, featureDiff.getPrevious());
+ assertEquals(current, featureDiff.getCurrent());
+ }
+
@Test
public void frameworkPropertiesUpdated() {
Feature previous = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:0.9.0"));