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-org-apache-sling-feature-apiregions-model.git
The following commit(s) were added to refs/heads/master by this push:
new 66882a2 make impossible to add different regions with the same name
66882a2 is described below
commit 66882a29329525a4bd30dd89c74dfa8047604aa6
Author: stripodi <[email protected]>
AuthorDate: Thu Apr 11 13:25:20 2019 +0200
make impossible to add different regions with the same name
---
.../java/org/apache/sling/feature/apiregions/model/ApiRegions.java | 4 ++++
.../org/apache/sling/feature/apiregions/model/ApiRegionsTest.java | 6 ++++++
2 files changed, 10 insertions(+)
diff --git
a/src/main/java/org/apache/sling/feature/apiregions/model/ApiRegions.java
b/src/main/java/org/apache/sling/feature/apiregions/model/ApiRegions.java
index b6db357..aade675 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/model/ApiRegions.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/model/ApiRegions.java
@@ -40,6 +40,10 @@ public final class ApiRegions implements Iterable<ApiRegion>
{
throw new IllegalArgumentException("Impossible to create a new API
Region without specifying a valid name");
}
+ if (getByName(regionName) != null) {
+ throw new IllegalArgumentException("API Region '" + regionName +
"' already exists, please specifying a different valid name");
+ }
+
ApiRegion parent = regions.isEmpty() ? null : regions.peek(); // null
parent means 'root' in the hierarchy
ApiRegion newRegion = new ApiRegion(regionName, parent);
return regions.push(newRegion);
diff --git
a/src/test/java/org/apache/sling/feature/apiregions/model/ApiRegionsTest.java
b/src/test/java/org/apache/sling/feature/apiregions/model/ApiRegionsTest.java
index 71dadd3..ccd0724 100644
---
a/src/test/java/org/apache/sling/feature/apiregions/model/ApiRegionsTest.java
+++
b/src/test/java/org/apache/sling/feature/apiregions/model/ApiRegionsTest.java
@@ -110,4 +110,10 @@ public class ApiRegionsTest {
assertEquals(expected, actual);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void twoRegionsWithSameNameNotAccepted() {
+ apiRegions.addNew("granpa");
+ apiRegions.addNew("granpa");
+ }
+
}