Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

add assert to CategoryPath(String...) constructor

Shai Erera5be38bff380e
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java
index 61bd1548032..27f7a250888 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java
@@ -60,6 +60,7 @@ public class CategoryPath implements Comparable<CategoryPath> {
/** Construct from the given path components. */
public CategoryPath(String... components) {
+ assert components.length > 0 : "use CategoryPath.EMPTY to create an empty path";
this.components = components;
length = components.length;
}
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java b/lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java
index de5f233072e..522ba787b0f 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java
@@ -46,7 +46,6 @@ public class FacetIndexingParamsTest extends LuceneTestCase {
assertEquals("3 characters should be written", 3, numchars);
assertEquals("wrong drill-down term text", expectedDDText, new String(
buf, 0, numchars));
- CategoryListParams clParams = dfip.getCategoryListParams(null);
assertEquals("partition for all ordinals is the first", "",
PartitionsUtils.partitionNameByOrdinal(dfip, 250));
assertEquals("for partition 0, the same name should be returned",
@@ -75,7 +74,7 @@ public class FacetIndexingParamsTest extends LuceneTestCase {
PathPolicy pathPolicy = PathPolicy.ALL_CATEGORIES;
assertEquals("path policy does not match default for root", pathPolicy.shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp));
for (int i = 0; i < 30; i++) {
- int nComponents = random().nextInt(10);
+ int nComponents = random().nextInt(10) + 1;
String[] components = new String[nComponents];
for (int j = 0; j < components.length; j++) {
components[j] = (Integer.valueOf(random().nextInt(30))).toString();
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestCategoryPath.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestCategoryPath.java
index ccaaf4d33ec..ce3f29f7634 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestCategoryPath.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestCategoryPath.java
@@ -131,9 +131,6 @@ public class TestCategoryPath extends LuceneTestCase {
CategoryPath p = new CategoryPath("hello", "world", "yo");
assertEquals(3, p.length);
assertEquals("hello/world/yo", p.toString('/'));
-
- p = new CategoryPath(new String[0]);
- assertEquals(0, p.length);
}
@Test
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
index 33168b0b6ef..2225f96ade3 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
@@ -353,7 +353,7 @@ public class TestTaxonomyCombined extends LuceneTestCase {
}
// test TaxonomyReader.getCategory():
- for (int i=0; i<tr.getSize(); i++) {
+ for (int i = 1; i < tr.getSize(); i++) {
CategoryPath expectedCategory = new CategoryPath(expectedCategories[i]);
CategoryPath category = tr.getPath(i);
if (!expectedCategory.equals(category)) {
@@ -367,7 +367,7 @@ public class TestTaxonomyCombined extends LuceneTestCase {
assertNull(tr.getPath(TaxonomyReader.INVALID_ORDINAL));
// test TaxonomyReader.getOrdinal():
- for (int i=0; i<expectedCategories.length; i++) {
+ for (int i = 1; i < expectedCategories.length; i++) {
int expectedOrdinal = i;
int ordinal = tr.getOrdinal(new CategoryPath(expectedCategories[i]));
if (expectedOrdinal != ordinal) {